﻿/***************************************************************************************************
名称 pmap.js v1.0
描述 用于实现地图对象
创建时间 2014-05-27

2014-06-09
修复ie下marker和title对象卡的问题，弃用raphael的marker和title实现接口

2014-06-10
实现marker和title对象的删除功能，实现drawmode时的title提示。
2014-06-16 
重写平移和缩放控件
2014-06-17
修复ie和非ie情况下event.button取值不一致的情况
2014-08-04
修复marker seticon函数
2014-08-06
实现Marker和Title相关接口
2014-08-07
修复在jquery-ui dialog控件下的	
map_panel_start_x和map_panel_start_y参数问题，目前更新部分放在map_paint中
2014-09-02
修复地图模式和地图比例尺的错误
2014-09-16
修复地图图标在chrome和firefox下的兼容性问题
2014-11-24
添加图层管理功能,尝试500点位下的实时响应功能
2015-04-21
删除图层(map_layer_info)相关代码,优化marker类的重绘,实现300个marker点标注下的地图服务.
2015-04-22
map_info变量单独保存为mapInfo.js文件,由用户生成,方便换底图数据
20515-04-24
地图最大级数map_max_layer不再静态设定，由读取map_info获得
****************************************************************************************************/ 
//获取显示范围
var	map_div_id					//父div的id
var	map_max_layer				//最大地图放大级数
var	map_current_layer			//地图当前级数

var	map_panel_start_x			//地图panel起始像素点位置,x方向
var	map_panel_start_y			//地图panel起始像素点位置,y方向
var	map_panel_size_x			//地图panel宽，单位为像素，x方向
var	map_panel_size_y			//地图panel高，单位为像素，y方向
var	map_max_tile_x				//覆盖地图显示所需瓦片数目，x方向
var	map_max_tile_y				//覆盖地图显示所需瓦片数目，y方向

var draw_callback				
//var	map_info					//地图配置信息，通过ajax获得数据初始化，结构参考php目录下的map_layer
								/*地图层类
								* 二维数组保存
								* map_info[j][0]表示layer_number 即放大级数
								* map_info[j][1]表示pixel_x 即x轴方向像素点数
								* map_info[j][2]表示pixel_y 即y轴方向像素点数
								* map_info[j][3]表示tile_x_min 即瓦片阵列x轴方向最小值
								* map_info[j][4]表示tile_y_min 即瓦片阵列Y轴方向最小值
								* map_info[j][5]表示lng_min 即当前地图经度最小值
								* map_info[j][6]表示lat_min 即当前地图纬度最小值
								* map_info[j][7]表示lng_max 即当前地图经度最大值
								* map_info[j][8]表示lat_max	即当前地图纬度最大值
								*/


var draw_mode="pan";  			//地图绘图模式
var rap							//地图绘图对象

var map_canvas					//map_canvas绘图对象
var map_panel_widget			//添加地图面板对象
var map_panel_cover				//添加面板下的地图前置图层，用于保护地图瓦片img标签的特性
var map_panel_base				//底图画板,用于显示256*256像素瓦片
var map_panel_overlay			//基础图层,用于显示道路信息
var map_source_widget 			//div类型，用于地图切换
var map_source_type=0			//0代表街道图，1代表卫星图
var map_gps_widget				//div类型，用于map右下角gps信息

var	map_to_panel_x				//当前显示最左上角地图块，相对地图panel的位置，x方向,瓦片内偏移量
var	map_to_panel_y				//当前显示最左上角地图块，相对地图panel的位置，y方向,瓦片内偏移量
var	map_to_whole_x				//当前显示地图块，整个地图的位置，x方向
var	map_to_whole_x_premove		//当前显示地图块，整个地图的位置，x方向，拖动前位置
var	map_to_whole_y				//当前显示地图块，整个地图的位置，y方向
var	map_to_whole_y_premove		//当前显示地图块，整个地图的位置，y方向，拖动前位置

var	map_onclick=0				//地图拖动时使用，标示鼠标是否按下状态
var map_inputform1=null;		//地图绘图模式变化时传入参数1
var map_inputform2=null;		//地图绘图模式变化时传入参数2
var _callback					//地图绘图模式变化时传入参数3 回调函数

var	map_mouse_down_x			//地图拖动时使用，标示鼠标是否按下位置，相对于显示器左上角，像素为单位，x方向
var	map_mouse_down_y			//地图拖动时使用，标示鼠标是否按下位置，相对于显示器左上角，像素为单位，y方向
var temp_str

var map_zoomAndPan_widget		//地图缩放和平移控件

var Marker_src="";				//绘制地图标注时候的数据源 string合适
var marker_onDrawMode;			//绘图模式时提示性标注
var title_onDrawMode;			//绘图模式时提示性文字提示
var map_pen;					//地图画笔，调色板

var ie678 = !-[1,]; 
function getButton(e){ 
	var code = e.button; 
	var ie678Map = { 
	1 : 0, 
	4 : 1, 
	2 : 2 
	} 
	if(ie678){ 
		return ie678Map[code]; 
		} 
	return code; 
} 
function nocontextmenu(e){ 

	if(e)
	{ 
		e.cancelBubble=true;
		e.preventDefault();
		e.stopPropagation();
	}
	else
	{
		event.cancelBubble=true;
		event.returnValue = false;
	}
} 
function setPen(color,weight,opacity,fillcolor,arrow,dash)
{
	if(map_pen==null)
	{
		map_pen=new Pen(color,weight,opacity,fillcolor,arrow,dash)
	}
	else
	{
		if(color!=null)
			map_pen.color=color;
		if(weight!=null)
			map_pen.weight=weight;
		if(opacity!=null)
			map_pen.opacity=opacity;
		if(fillcolor!=null)
			map_pen.fillcolor=fillcolor;
		if(arrow!=null)
			map_pen.arrow=arrow;
		if(dash!=null)
			map_pen.dash=dash;
	}
}
//地图初始化，生成地图子对象
function map_init()
{
	document.oncontextmenu = nocontextmenu;
	//添加地图面板对象
	map_panel_widget=document.createElement('div');
	document.getElementById(map_div_id).appendChild(map_panel_widget);;
	map_panel_widget.style.position="absolute";
	map_panel_widget.style.overflow="hidden";
	map_panel_widget.style.left="0px";
	map_panel_widget.style.top="0px";
	map_panel_widget.style.width=map_panel_size_x+"px";
	map_panel_widget.style.height=map_panel_size_y+"px";
	map_panel_widget.style.cursor="pointer";
	//添加面板下的地图前置图层，用于保护地图瓦片img标签的特性
	
	map_panel_cover=document.createElement('div');
	map_panel_widget.appendChild(map_panel_cover);
	map_panel_cover.style.position="absolute";
	map_panel_cover.style.left="0px";
	map_panel_cover.style.top="0px";
	map_panel_cover.style.width=map_panel_size_x+"px";
	map_panel_cover.style.height=map_panel_size_y+"px";
	map_panel_cover.style.zIndex="200";

	
	//底图,用于显示256*256像素瓦片
	
	map_panel_base=document.createElement('div');
	map_panel_widget.appendChild(map_panel_base);
	map_panel_base.style.position="absolute";
	map_panel_base.style.left="0px";
	map_panel_base.style.top="0px";
	map_panel_base.style.width=map_panel_size_x+"px";
	map_panel_base.style.height=map_panel_size_y+"px";
	map_panel_base.style.zIndex="100";
	//添加面板下的地图瓦片
	for(var j=0;j<map_max_tile_y;j++)
	{
		for(var i=0;i<map_max_tile_x;i++)
		{
			map_panel_base.appendChild(document.createElement('div'));
		}
	}
	//基础图层,包含道路信息

	map_panel_overlay=document.createElement('div');
	map_panel_widget.appendChild(map_panel_overlay);
	map_panel_overlay.style.position="absolute";
	map_panel_overlay.style.left="0px";
	map_panel_overlay.style.top="0px";
	map_panel_overlay.style.width=map_panel_size_x+"px";
	map_panel_overlay.style.height=map_panel_size_y+"px";
	map_panel_overlay.style.zIndex="100";
	//添加面板下的地图瓦片
	for(var j=0;j<map_max_tile_y;j++)
	{
		for(var i=0;i<map_max_tile_x;i++)
		{
			map_panel_overlay.appendChild(document.createElement('div'));
		}
	}
	//添加地图绘图对象，用于绘制图形
	map_canvas=document.createElement('div');
	map_panel_widget.appendChild(map_canvas);
	map_canvas.style.position="absolute";
	map_canvas.style.left=0+"px";
	map_canvas.style.top=0+"px";
	map_canvas.style.width=map_panel_size_x+"px";
	map_canvas.style.height=map_panel_size_y+"px";
	map_canvas.style.zIndex="200";
	map_canvas.id="rapdiv";
	rap=new rapGraphics(rapdiv,map_panel_size_x,map_panel_size_y);

	//设置在绘图模式时候的提示用marker和title
	marker_onDrawMode=new Marker(new Point(0,0),null);
	rap.add_system_overlay(marker_onDrawMode);
	marker_onDrawMode.disableEdit();
	marker_onDrawMode.setZIndex(-1);
	
	title_onDrawMode=new Title("",14,7,"宋体","blue","white","gray",1);
	rap.add_system_overlay(title_onDrawMode);
	title_onDrawMode.disableEdit();
	title_onDrawMode.setZIndex(-1);
	
	//添加地图模式信息
	map_source_widget=document.createElement('div');
	document.getElementById(map_div_id).appendChild(map_source_widget);
	map_source_widget.style.position="absolute";
	map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/satellite.jpg')"
	map_source_widget.style.left=map_panel_size_x-110+"px";
	map_source_widget.title="显示卫星地图";
	map_source_widget.style.top=60+"px";
	map_source_widget.style.width=49+"px";
	map_source_widget.style.height=51+"px";
	map_source_widget.style.zIndex="300";
	map_source_widget.onclick=function(e)
	{
		preventBubble(e); 
		if(map_source_type==0)
		{
			map_source_type=1;
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/road.jpg')";
			map_source_widget.title="显示普通地图";
			map_gps_widget.style.color="white";
			map_paint();
		}
		else
		{
			map_source_type=0;
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/satellite.jpg')";
			map_source_widget.title="显示卫星地图";
			map_gps_widget.style.color="black";
			map_paint();
		}
	};
	map_source_widget.onmouseover=function(e){
		preventBubble(e); 
		if(map_source_type==0)
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/satellite_onfocus.jpg')"
		else
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/road_onfocus.jpg')"
	};
	map_source_widget.onmouseout=function(e){
		preventBubble(e); 
		if(map_source_type==0)
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/satellite.jpg')"
		else
			map_source_widget.style.backgroundImage="url('../static/mapService/images/icon/road.jpg')"
	};
	//添加地图鼠标经纬度信息
	map_gps_widget=document.createElement('div');
	document.getElementById(map_div_id).appendChild(map_gps_widget);
	map_gps_widget.style.position="absolute";
	map_gps_widget.style.textAlign="right";
	map_gps_widget.style.left=0+"px";
	map_gps_widget.style.top=map_panel_size_y-20+"px";
	map_gps_widget.style.width=map_panel_size_x+"px";
	map_gps_widget.style.height=20+"px";
	map_gps_widget.style.zIndex="300";
	map_gps_widget.style.color="black";
	map_gps_widget.style.fontSize="12px";
	
	
	//添加地图缩放平移控件 2014/6/16 重写平移和缩放控件
	map_zoomAndPan_widget=document.createElement('div');
	document.getElementById(map_div_id).appendChild(map_zoomAndPan_widget);
	map_zoomAndPan_widget.style.position="absolute";
	map_zoomAndPan_widget.style.left=48+"px";
	map_zoomAndPan_widget.style.top=48+"px";
	map_zoomAndPan_widget.style.width=48+"px";
	map_zoomAndPan_widget.style.height=400+"px";
	map_zoomAndPan_widget.style.zIndex="300";

	//添加地图平移控件 
	var map_pan_widget=document.createElement('div');
	map_zoomAndPan_widget.appendChild(map_pan_widget);
	map_pan_widget.style.position="absolute";
	map_pan_widget.style.width=48+"px";
	map_pan_widget.style.height=48+"px";
	map_pan_widget.style.zIndex="300";
	map_pan_widget.style.background="url('../static/mapService/images/icon/pan.png') no-repeat";
	map_pan_widget.onmousemove=function(e)
	{
	    preventBubble(e); 
		e = e || window.event;
		var mousePos = mouse_Position(e);
		var x=mousePos.x-parseFloat(map_zoomAndPan_widget.style.left.slice(0,-2))-map_panel_start_x-24;
		var y=mousePos.y-parseFloat(map_zoomAndPan_widget.style.top.slice(0,-2))-map_panel_start_y-24;
		//在图标圆内
		if((x*x+y*y)<24*24)
		{
			if((y<0&&x!=0&&Math.abs(y/x)>1)||(y<0&&x==0))
				map_pan_widget.style.background="url('../static/mapService/images/icon/up.png') no-repeat";
			if((y>0&&x!=0&&Math.abs(y/x)>1)||(y>0&&x==0))
				map_pan_widget.style.background="url('../static/mapService/images/icon/down.png') no-repeat";
			if(x<0&&Math.abs(y/x)<1)
				map_pan_widget.style.background="url('../static/mapService/images/icon/left.png') no-repeat";
			if(x>0&&Math.abs(y/x)<1)
				map_pan_widget.style.background="url('../static/mapService/images/icon/right.png') no-repeat";
		}
		else map_pan_widget.style.background="url('../static/mapService/images/icon/pan.png') no-repeat";
	}
	map_pan_widget.onmouseout=function(e)
	{
		preventBubble(e); 
		map_pan_widget.style.background="url('../static/mapService/images/icon/pan.png') no-repeat";
	}
	map_pan_widget.onclick=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
		var mousePos = mouse_Position(e);
		var x=mousePos.x-parseFloat(map_zoomAndPan_widget.style.left.slice(0,-2))-map_panel_start_x-24;
		var y=mousePos.y-parseFloat(map_zoomAndPan_widget.style.top.slice(0,-2))-map_panel_start_y-24;
		//在图标圆内
		if((x*x+y*y)<24*24)
		{
			if((y<0&&x!=0&&Math.abs(y/x)>1)||(y<0&&x==0))
			{
				map_to_whole_y-=150;
				map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
				map_paint();
			}
			if((y>0&&x!=0&&Math.abs(y/x)>1)||(y>0&&x==0))
			{
				map_to_whole_y+=150;
				map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
				map_paint();
			}
			if(x<0&&Math.abs(y/x)<1)
			{
				map_to_whole_x-=150;
				map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
				map_paint();
			}
			if(x>0&&Math.abs(y/x)<1)
			{
				map_to_whole_x+=150;
				map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
				map_paint();
			}
		}
	}
	
	//添加缩放控件
	var map_zoom_in_widget=document.createElement('div');
	map_zoomAndPan_widget.appendChild(map_zoom_in_widget);
	map_zoom_in_widget.style.position="absolute";
	map_zoom_in_widget.style.left=15+"px";
	map_zoom_in_widget.style.top=58+"px";
	map_zoom_in_widget.style.width=17+"px";
	map_zoom_in_widget.style.height=17+"px";
	map_zoom_in_widget.style.zIndex="300";
	map_zoom_in_widget.style.background="url('../static/mapService/images/icon/zoom_in_bar.png') no-repeat";
	map_zoom_in_widget.onclick=function(e)
	{
		preventBubble(e); 
		map_zoom_in();
	}
	map_zoom_in_widget.onmousemove=function(e)
	{
		preventBubble(e); 
	}
	
	//添加缩放控件
	var map_zoom_out_widget=document.createElement('div');
	map_zoomAndPan_widget.appendChild(map_zoom_out_widget);
	map_zoom_out_widget.style.position="absolute";
	map_zoom_out_widget.style.left=15+"px";
	map_zoom_out_widget.style.top=219+"px";
	map_zoom_out_widget.style.width=17+"px";
	map_zoom_out_widget.style.height=17+"px";
	map_zoom_out_widget.style.zIndex="300";
	map_zoom_out_widget.style.background="url('../static/mapService/images/icon/zoom_out_bar.png') no-repeat";
	map_zoom_out_widget.onclick=function(e)
	{
		preventBubble(e); 
		map_zoom_out();
	}
	map_zoom_out_widget.onmousemove=function(e)
	{
		preventBubble(e); 
	}
	
	//添加缩放竖条控件
	var map_zoom_sliderbar_widget=document.createElement('div');
	map_zoomAndPan_widget.appendChild(map_zoom_sliderbar_widget);
	map_zoom_sliderbar_widget.style.position="absolute";
	map_zoom_sliderbar_widget.style.left=0+"px";
	map_zoom_sliderbar_widget.style.top=75+"px";
	map_zoom_sliderbar_widget.style.width=48+"px";
	map_zoom_sliderbar_widget.style.height=144+"px";
	map_zoom_sliderbar_widget.style.zIndex="300";
	map_zoom_sliderbar_widget.style.background="url('../static/mapService/images/icon/sliderbar.png') no-repeat";
	
	map_zoom_sliderbar_widget.onmousemove=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
		var mousePos = mouse_Position(e)
		var x=mousePos.x-parseFloat(map_zoomAndPan_widget.style.left.slice(0,-2))-map_panel_start_x;
	
		var y=mousePos.y-parseFloat(map_zoomAndPan_widget.style.top.slice(0,-2))-map_panel_start_y-75;
		
	
		if(getButton(e)==0)
		{ 
			if(map_zoom_slider_widget_onclick)
			{
				if(x>16&&x<33)
				{   
				    if(y<0)
					{
						y=0;
						map_zoom_slider_widget_onclick=false;
					}
					if(y>136)
					{
					    y=136;
					}
					if(y>144)
					{
						map_zoom_slider_widget_onclick=false;
					}
					map_zoom_adjust(map_panel_size_x/2+map_panel_start_x,map_panel_size_y/2+map_panel_start_y,map_current_layer,18-Math.floor(y/8));
					map_current_layer=18-Math.floor(y/8);
					map_paint();
					map_zoom_slider_widget.style.top=y+"px";
				}
				else map_zoom_slider_widget_onclick=false
			}
		}
	}
	map_zoom_sliderbar_widget.onclick=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
		var mousePos = mouse_Position(e)
		var x=mousePos.x-parseFloat(map_zoomAndPan_widget.style.left.slice(0,-2))-map_panel_start_x;	
		var y=mousePos.y-parseFloat(map_zoomAndPan_widget.style.top.slice(0,-2))-map_panel_start_y-75;
		map_zoom_adjust(map_panel_size_x/2+map_panel_start_x,map_panel_size_y/2+map_panel_start_y,map_current_layer,18-Math.floor(y/8));
		map_current_layer=18-Math.floor(y/8);
		map_paint();	
		map_zoom_slider_widget.style.top=144-8*map_current_layer+"px";				
	}
	map_zoom_sliderbar_widget.onmouseup=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
		var mousePos = mouse_Position(e);
		var x=mousePos.x-parseFloat(map_zoomAndPan_widget.style.left.slice(0,-2))-map_panel_start_x;
		
		var y=mousePos.y-parseFloat(map_zoomAndPan_widget.style.top.slice(0,-2))-map_panel_start_y-75;
		if(getButton(e)==0)
		{  
		    map_zoom_slider_widget.style.top=144-8*map_current_layer+"px";
			map_zoom_slider_widget_onclick=false;
		}
	}
	map_zoom_sliderbar_widget.onmousedown=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
	}
	//添加缩放横条控件
	var map_zoom_slider_widget_onclick=false;
	map_zoom_slider_widget=document.createElement('div');
	map_zoom_sliderbar_widget.appendChild(map_zoom_slider_widget);
	map_zoom_slider_widget.style.position="absolute";
	map_zoom_slider_widget.style.left=15+"px";
	map_zoom_slider_widget.style.top=25+"px";
	map_zoom_slider_widget.style.width=17+"px";
	map_zoom_slider_widget.style.height=10+"px";
	map_zoom_slider_widget.style.zIndex="300";
	map_zoom_slider_widget.style.background="url('../static/mapService/images/icon/slider.png') no-repeat";
	map_zoom_slider_widget.onmousedown=function(e)
	{
		preventBubble(e); 
		e = e || window.event;
		if(getButton(e)==0)
		{  
			map_zoom_slider_widget_onclick=true;
		}
	}

	window.onresize=function(e)
	{
		map_panel_size_x=parseInt($("#"+map_div_id).width());
		map_panel_size_y=parseInt($("#"+map_div_id).height());
		
		map_max_tile_x=Math.ceil(map_panel_size_x/256)+1;		//覆盖地图显示所需瓦片数目，x方向
		map_max_tile_y=Math.ceil(map_panel_size_y/256)+1;		//覆盖地图显示所需瓦片数目，y方向
		
		map_canvas.style.width=map_panel_size_x+"px";
		map_canvas.style.height=map_panel_size_y+"px";
		
		map_panel_widget.style.width=map_panel_size_x+"px";
		map_panel_widget.style.height=map_panel_size_y+"px";
		
		map_panel_cover.style.width=map_panel_size_x+"px";	
		map_panel_cover.style.height=map_panel_size_y+"px";
		
		map_panel_base.style.width=map_panel_size_x+"px";	
		map_panel_base.style.height=map_panel_size_y+"px";	
		
		map_source_widget.style.left=map_panel_size_x-110+"px";	
		
		map_gps_widget.style.top=map_panel_size_y-20+"px";
		map_gps_widget.style.width=map_panel_size_x+"px";		
		map_paint();
	}
	//设置鼠标监听程序
	$("#"+map_div_id).mousedown(mouse_down);
	$("#"+map_div_id).mouseup(mouse_up);
	$("#"+map_div_id).mousemove(mouse_move);
	$("#"+map_div_id).mouseleave(mouse_leave);
	//使用js的mousewheel插件
	$("#"+map_div_id).bind('mousewheel',mouse_wheel);
	//绘制地图
	map_to_whole_x=map_info[map_current_layer][1]/2-map_panel_size_x/2;										//当前显示地图块，整个地图的位置，x方向
								//当前显示地图块，整个地图的位置，x方向，拖动前位置
	map_to_whole_y=map_info[map_current_layer][2]/2-map_panel_size_y/2;	
	map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
	map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
	map_paint();
}


//通过ajax获取地图配置信息
function map_load_info()
{
	/*地图层类
	* 二维数组保存
	* map_info[j][0]表示layer_number 即放大级数
	* map_info[j][1]表示pixel_x 即x轴方向像素点数
	* map_info[j][2]表示pixel_y 即y轴方向像素点数
	* map_info[j][3]表示tile_x_min 即瓦片阵列x轴方向最小值
	* map_info[j][4]表示tile_y_min 即瓦片阵列Y轴方向最小值
	* map_info[j][5]表示lng_min 即当前地图经度最小值
	* map_info[j][6]表示lat_min 即当前地图纬度最小值
	* map_info[j][7]表示lng_max 即当前地图经度最大值
	* map_info[j][8]表示lat_max	即当前地图纬度最大值
	*/
	
	//静态获取地图状态信息
	
	if(typeof(map_info)=='undefined')
	{
		alert("please import \"mapInfo.js\" file");
	}
	map_init();
}

//鼠标按下响应函数
function mouse_down(e)
{   
    e = e || window.event;
	var mousePos = mouse_Position(e);
	switch(draw_mode)
	{
		case "pan":
			if(getButton(e)==0)
				map_onclick=1;
			map_to_whole_x_premove=map_to_whole_x;
			map_to_whole_y_premove=map_to_whole_y;

			map_mouse_down_x=mousePos.x;
			map_mouse_down_y=mousePos.y;
			break;
		case "drawCircle":	  
		case "drawRect":
		case "zoomInExt":
		case "zoomOutExt":
			if(getButton(e)==0)
				map_onclick=1;
			map_to_whole_x_premove=map_to_whole_x;
			map_to_whole_y_premove=map_to_whole_y;
			map_mouse_pre_x=mousePos.x;
			map_mouse_pre_y=mousePos.y;
			break;
		default:
			break;
	}
	e.preventDefault();	
	e.stopPropagation();
}
//鼠标弹起响应函数
function mouse_up(e)
{   
    e = e || window.event;
	var mousePos = mouse_Position(e);
	switch(draw_mode)
    { 
		case "pan":
			map_onclick=0;
			break;
		case "drawPoint":
			draw_mode="pan";
			//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			title_onDrawMode.setName("");
			rap.repaint_overlay();
			temp_str=""+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			if(_callback!=null)
			{
				_callback(temp_str);
				_callback=null;
			}
			temp_str="";
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			break;
		case "drawMarker":
			draw_mode="pan";
			//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			rap.repaint_overlay();
			
			var pIcon=new Icon();
			pIcon.image=Marker_src;
			pIcon.height=24;
			pIcon.width=24;

			marker_onDrawMode.setPoint("0,0");
			title_onDrawMode.setName("");

			var pMarker=new Marker(new Point(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer),y_to_lat(mousePos.y-map_panel_start_y,map_current_layer)),pIcon);
			rap.add_overlay(pMarker);

			temp_str=""+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			if(_callback!=null)
			{
				_callback(temp_str);
				_callback=null;
			}
			Marker_src="";
			temp_str="";
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			
			break;
		case "drawText":
			draw_mode="pan";
			//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			rap.repaint_overlay();
			title_onDrawMode.setName("");
			var pTitle=new Title(Marker_src,14,7,"宋体","blue","yellow","red",1);
			pTitle.setPoint(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer));
			rap.add_overlay(pTitle);
			temp_str=""+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			if(_callback!=null)
			{
				_callback(temp_str);
				_callback=null;
			}
			Marker_src="";
			temp_str="";
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			
			break;
		case "measure":
			//左键画线
			if(getButton(e)==0)
			{
				//测距第一次按下,起点显示
				if(map_onclick==0)
				{
					temp_str=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
					var pPoint=new Overlay_Point(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"red", 1,1,"white");
					pPoint.setZIndex(-2);
					rap.add_system_overlay(pPoint);
					var pTitle=new Title("起点",14,7,"宋体","black","white","red",1);
					pTitle.setPoint(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+20-map_panel_start_y,map_current_layer));
					pTitle.setZIndex(-2);
					rap.add_system_overlay(pTitle);
				}
				//测距非第一次按下，显示分段距离
				else
				{
					temp_str+=","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
				
					var arr=temp_str.split(",")
					var pPolyline=new Polyline(arr[arr.length-4]+","+arr[arr.length-3]+","+arr[arr.length-2]+","+arr[arr.length-1],"#FFA500", 3,0.8,0);
					pPolyline.setZIndex(-3);
					rap.add_system_overlay(pPolyline);
						
					var pPoint=new Overlay_Point(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"red", 1,1,"white");
					pPoint.setZIndex(-2);
					rap.add_system_overlay(pPoint);

					var length=lnglat_to_kilometer(arr[arr.length-4],arr[arr.length-3],arr[arr.length-2],arr[arr.length-1]);
					if(length<1)
						length=(length*1000).toFixed(1)+"米";
					else
						length=length.toFixed(1)+"公里";
					var pTitle=new Title(length,14,7,"宋体","black","white","red",1);
					pTitle.setZIndex(-2);
					pTitle.setPoint(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+20-map_panel_start_y,map_current_layer));
					rap.add_system_overlay(pTitle);
				}
				map_onclick++;
			}
			//测距结束，显示总距离
			else if(getButton(e)==2)
			{
				var arr=temp_str.split(",");
				var length=0;
				for(var i=0;i<arr.length-3;i=i+2)
					length+=lnglat_to_kilometer(arr[i],arr[i+1],arr[i+2],arr[i+3]);
				if(length<1)
					length=(length*1000).toFixed(1)+"米";
				else
					length=length.toFixed(1)+"公里";	
				var pTitle=new Title("总长:"+length,14,7,"宋体","black","white","red",1);
				pTitle.setPoint(arr[arr.length-2]+","+y_to_lat(lat_to_y(arr[arr.length-1],map_current_layer)+20,map_current_layer));
				pTitle.setZIndex(-2);
				title_onDrawMode.setName("");
				rap.add_system_overlay(pTitle);
					
				map_onclick=0;
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
				if(_callback!=null)
				{
					_callback(temp_str);
					_callback=null;
				}
				temp_str="";
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			}
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			break;
		case "drawPolyline":
			//左键画线
			if(getButton(e)==0)
			{
				if(map_onclick==0)
					temp_str=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
				else temp_str+=","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
				rap.repaint_overlay();
				rap.drawPolyline(temp_str,map_pen.color,map_pen.weight,map_pen.opacity,map_pen.arrow);
				
				map_onclick++;
			}
			else if(getButton(e)==2)
			{
				var pPolyline=new Polyline(temp_str,map_pen.color, map_pen.weight,map_pen.opacity,map_pen.arrow);
				title_onDrawMode.setName("");
				rap.add_overlay(pPolyline);
				map_onclick=0;
				if(_callback!=null)
				{
					_callback(temp_str);
					_callback=null;
				}
				temp_str="";
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			}
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			break;
		case "drawRect":
			if(getButton(e)==0)
			{
				map_onclick=0;
				var pRect=new Rectangle(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"#ff00FF", 2,0.3,"blue");
				title_onDrawMode.setName("");
				rap.add_overlay(pRect);
				if(_callback!=null)
				{
					_callback(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer));
					_callback=null;
				}
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			}
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			break;
		case "drawCircle":
			if(getButton(e)==0)
			{
				map_onclick=0;
				var r=Math.sqrt(mousePos.x*mousePos.x+map_mouse_pre_x*map_mouse_pre_x-2*mousePos.x*map_mouse_pre_x+mousePos.y*mousePos.y+map_mouse_pre_y*map_mouse_pre_y-2*mousePos.y*map_mouse_pre_y);
				var pCircle=new Circle(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+(x_to_lng(map_mouse_pre_x-map_panel_start_x+Math.round(r),map_current_layer)-x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)),"#ff00FF", 2,0.3,"blue");
				title_onDrawMode.setName("");		
				rap.add_overlay(pCircle);
				if(_callback!=null)
				{
					_callback(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+(x_to_lng(map_mouse_pre_x-map_panel_start_x+Math.round(r),map_current_layer)-x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)));
					_callback=null;
				}
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			}
			break;
		case "drawPolygon":
	  	//左键画线
			if(getButton(e)==0)
			{
				if(map_onclick==0)
					temp_str=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
				else temp_str+=","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
				map_onclick++;
			}
			else if(getButton(e)==2)
			{
				map_onclick=0;
				var pPolygon=new Polygon(temp_str,map_pen.color, map_pen.weight,map_pen.opacity,map_pen.fillcolor);
				title_onDrawMode.setName("");	
				rap.add_overlay(pPolygon);
				if(_callback!=null)
				{
					_callback(temp_str);
					_callback=null;
				}
				temp_str="";
				draw_mode="pan";
				//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
			}
			if(	map_inputform1)
				map_inputform1.value=x_to_lng(mousePos.x-map_panel_start_x,map_current_layer);
			if(	map_inputform2)	
				map_inputform2.value=y_to_lat(mousePos.y-map_panel_start_y,map_current_layer);
			break;
		case "zoomInExt":
		case "zoomOutExt":
			if(getButton(e)==0)
			{
				map_onclick=0;
				var x1=x_to_lng(Math.min(mousePos.x,map_mouse_pre_x)-map_panel_start_x,map_current_layer);
				var x2=x_to_lng(Math.max(mousePos.x,map_mouse_pre_x)-map_panel_start_x,map_current_layer);
				var y1=y_to_lat(Math.min(mousePos.y,map_mouse_pre_y)-map_panel_start_y,map_current_layer);
				var y2=y_to_lat(Math.max(mousePos.y,map_mouse_pre_y)-map_panel_start_y,map_current_layer);
			
				var lng=x1/2+x2/2;
				var lat=y1/2+y2/2;
				if(lng<map_info[map_current_layer][5]||lat<map_info[map_current_layer][6]||lng>map_info[map_current_layer][7]||lat>map_info[map_current_layer][8])
					return ;
			
				if(draw_mode=="zoomInExt")	
				{
					map.centerAndZoom(new Point(lng,lat),map_current_layer+1);
					var pRect=new Rectangle(x1+","+y1+","+x2+","+y2,"blue", 5,0,"#FFFFFF",1);
					rap.add_overlay(pRect);
					setTimeout(function(){
						rap.remove_overlay(pRect);
					},1000);
					draw_mode="pan";
					//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
		
				}
				else if(draw_mode=="zoomOutExt")	
				{
					map.centerAndZoom(new Point(lng,lat),map_current_layer-1);
					var pRect=new Rectangle(x1+","+y1+","+x2+","+y2,"blue", 5,0,"#FFFFFF",1);
					title_onDrawMode.setName("");		
					rap.add_overlay(pRect);
					setTimeout(function(){
						rap.remove_overlay(pRect);
					},1000);
					draw_mode="pan";
					//document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
				}
			}   
			break;	
		default:
			break;	  
    }		
	e.preventDefault();
	e.stopPropagation();	
}
//鼠标移动响应函数
function mouse_move(e)
{  
   	e = e || window.event;
	var mousePos = mouse_Position(e);
    map_set_gps(mousePos.x,mousePos.y)
   switch(draw_mode)
   {  
		case "pan":
			if(map_onclick==1&&getButton(e)==0)
			{   
				map_to_whole_x=map_to_whole_x_premove+map_mouse_down_x-mousePos.x;
				map_to_whole_y=map_to_whole_y_premove+map_mouse_down_y-mousePos.y;
				map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
				map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
				map_paint();			
			}
			
			break;		
		case "drawPoint":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+80-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("点击左键，获取坐标");
			}
			break;
		case "drawMarker":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				var pIcon=new Icon();
				pIcon.image=Marker_src;
				pIcon.height=24;
				pIcon.width=24;
				
				marker_onDrawMode.setPoint(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer));
				marker_onDrawMode.setIcon(pIcon);
	
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+80-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("点击左键，绘制图标");
			}
			break;
		case "drawText":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName(Marker_src);
			
			}
			break;
		case "drawRect":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("按住左键开始");
			}	
			else if(map_onclick==1)
			{  
				rap.repaint_overlay();
				rap.drawRectangle(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"#ff00FF", 2,0.3,"blue");
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("释放左键结束");
			}
			break;
		case "drawCircle":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("按住左键开始");
			}	
			else if(map_onclick==1)
			{  
				rap.repaint_overlay();
				var r=Math.sqrt(mousePos.x*mousePos.x+map_mouse_pre_x*map_mouse_pre_x-2*mousePos.x*map_mouse_pre_x+mousePos.y*mousePos.y+map_mouse_pre_y*map_mouse_pre_y-2*mousePos.y*map_mouse_pre_y);		   
				rap.drawCircle(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+(x_to_lng(map_mouse_pre_x-map_panel_start_x+Math.round(r),map_current_layer)-x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)),"#ff00FF", 2,0.3,"blue");
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("释放左键结束");
			}
			break;
		case "measure":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("单击左键确定起点");
			}
			else if(map_onclick>0)
			{
				rap.repaint_overlay();
				var arr=temp_str.split(",");
				var length=0;
				for(var i=0;i<arr.length-3;i=i+2)
					length+=lnglat_to_kilometer(arr[i],arr[i+1],arr[i+2],arr[i+3]);
				length+=lnglat_to_kilometer(arr[arr.length-2],arr[arr.length-1],x_to_lng(mousePos.x-map_panel_start_x,map_current_layer),y_to_lat(mousePos.y-map_panel_start_y,map_current_layer));
				if(length<1)
					length=(length*1000).toFixed(1)+"米";
				else
					length=length.toFixed(1)+"公里";	
						
				rap.drawPolyline(+arr[arr.length-2]+","+arr[arr.length-1]+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"#FFA500",3,0,0);
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("总长:"+length+"\n单击确定地点,右键结束");			
			}
			break;
		case "drawPolyline":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+90-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("单击左键开始，右键结束");
			}
			else if(map_onclick>0)
			{
				rap.repaint_overlay();
				rap.drawPolyline(temp_str+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),map_pen.color,map_pen.weight,map_pen.opacity,map_pen.arrow);
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+85-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("左键绘制，右键结束");
			}
			break;
		case "drawPolygon":
    		if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+90-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("单击左键开始，右键结束");
			}
			else if(map_onclick>0)
			{
				rap.repaint_overlay();
				rap.drawPolygon(temp_str+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),map_pen.color,map_pen.weight,map_pen.opacity,map_pen.fillcolor);
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+85-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("左键绘制，右键结束");	
			}
			break;
		case "zoomInExt":
		case "zoomOutExt":
			if(map_onclick==0)
			{
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+60-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("按住左键开始");
			}
			else if(map_onclick==1)
			{  
				rap.repaint_overlay();
				title_onDrawMode.setPoint(x_to_lng(mousePos.x+70-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y+30-map_panel_start_y,map_current_layer));
				title_onDrawMode.setName("释放左键进行缩放");				
				rap.drawRectangle(x_to_lng(map_mouse_pre_x-map_panel_start_x,map_current_layer)+","+y_to_lat(map_mouse_pre_y-map_panel_start_y,map_current_layer)+","+x_to_lng(mousePos.x-map_panel_start_x,map_current_layer)+","+y_to_lat(mousePos.y-map_panel_start_y,map_current_layer),"blue", 5,0,"#FFFFFF",1);
			}	    
			break;	  
		default:
			break;   
	}
	e.preventDefault();	
	e.stopPropagation();
}
function mouse_leave(e)
{	
	if(draw_mode=="pan")
	{
		map_onclick=0;
	}	
	e.preventDefault();
	e.stopPropagation();
}
function mouse_wheel(e,delta)
{
	if(draw_mode=="pan"||draw_mode=="measure")
	{
		//根据滚轮方向放大和缩小
		delta=delta/120;
		if (delta <0)
			map_zoom_out(e)
		else if(delta >0)
			map_zoom_in(e)
	}
	e.preventDefault();
	e.stopPropagation();
}
function mouse_Position (e)
{ 
	if(e==null)
	{
		return {x:(document.body.clientWidth/2),y:(document.body.clientHeight/2)};
	}
	if(e.pageX || e.pageY){ 
		return {x:e.pageX, y:e.pageY}; 
	} 
	return { 
		x:e.clientX + document.body.scrollLeft - document.body.clientLeft, 
		y:e.clientY + document.body.scrollTop - document.body.clientTop 
	}; 
}

//阻止事件冒泡
function preventBubble(e)
{  
	if(e)
	{ 
		e.cancelBubble=true;
		e.preventDefault();
		e.stopPropagation();
	}
	else
	{
		event.cancelBubble=true;
		event.returnValue = false;
	}
}



//地图级数调整时需要对地图中心坐标进行计算，实现鼠标位置放大前后经纬度不变。
function map_zoom_adjust(mouse_x,mouse_y,zoom_before_layer,zoom_after_layer)
{
	//获取上一状态最小点的像素值
	var pre_pix_min=lng_to_pixel(map_info[zoom_before_layer][5],zoom_before_layer);
	//获得鼠标所在点像素值,并计算该店经度
	var focus_lng=pixel_to_lng(pre_pix_min+map_to_whole_x+mouse_x-map_panel_start_x, zoom_before_layer);
	//计算当前状态最小点的像素值
	var current_pix_min=lng_to_pixel(map_info[zoom_after_layer][5],zoom_after_layer);
	//获取当前状态下的像素值
	map_to_whole_x=	Math.floor(lng_to_pixel(focus_lng,zoom_after_layer)-current_pix_min-(mouse_x-map_panel_start_x));		
	//获取上一状态最小点的像素值
	pre_pix_min=lat_to_pixel(map_info[zoom_before_layer][8],zoom_before_layer);
	//获得鼠标所在点像素值,并计算该店经度
	var focus_lat=pixel_to_lat(pre_pix_min+map_to_whole_y+mouse_y-map_panel_start_y, zoom_before_layer);
	//计算当前状态最小点的像素值
	current_pix_min=lat_to_pixel(map_info[zoom_after_layer][8],zoom_after_layer);
	//获取当前状态下的像素值

	map_to_whole_y=	Math.floor(lat_to_pixel(focus_lat,zoom_after_layer)-current_pix_min-(mouse_y-map_panel_start_y));
		
	if(map_to_whole_x>map_info[zoom_after_layer][1]||map_to_whole_y>map_info[zoom_after_layer][2]||map_to_whole_x+map_panel_size_x<0||map_to_whole_y+map_panel_size_y<0)
	{
		map_to_whole_x=map_info[zoom_after_layer][1]/2-map_panel_size_x/2;
		map_to_whole_y=map_info[zoom_after_layer][2]/2-map_panel_size_y/2;
	}
	map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
	map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
}
//地图放大 级数+1
function map_zoom_in(e)
{
	if(map_current_layer<map_max_layer)
	{
		var mousePos = mouse_Position(e);
		map_set_gps(mousePos.x,mousePos.y);
		map_current_layer++;
		map_zoom_adjust(mousePos.x,mousePos.y,map_current_layer-1,map_current_layer);
		map_paint();
	}
}
//地图缩小 级数-1
function map_zoom_out(e)
{
	if(map_current_layer>1)
	{
		var mousePos = mouse_Position(e);
		map_set_gps(mousePos.x,mousePos.y);
		map_current_layer--;
		map_zoom_adjust(mousePos.x,mousePos.y,map_current_layer+1,map_current_layer);
		map_paint();	
	}
}
//设置右下角GPS信息，默认用于显示鼠标位置的经纬度
function map_set_gps(mouse_x,mouse_y)
{
	if(mouse_x&&mouse_y)
	{
		//获取上一状态最小点的像素值
		var pre_pix_min=lng_to_pixel(map_info[map_current_layer][5],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var focus_lng=pixel_to_lng(pre_pix_min+map_to_whole_x+mouse_x-map_panel_start_x, map_current_layer);
		//计算当前状态最小点的像素值
		pre_pix_min=lat_to_pixel(map_info[map_current_layer][8],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var focus_lat=pixel_to_lat(pre_pix_min+map_to_whole_y+mouse_y-map_panel_start_y, map_current_layer);
	}
	else
	{
		var focus_lng=0;
		var focus_lat=0;
	}
	var scale=2257.00*Math.pow(2,18-map_current_layer);
	var pixels=0.6*Math.pow(2,18-map_current_layer);
	map_gps_widget.innerHTML="地图级别:"+map_current_layer+"&nbsp;比例尺:1/"+scale.toFixed(2)+"&nbsp;分辨率:"+pixels.toFixed(2)+"米/每像素&nbsp;&nbsp;&nbsp;"+"经纬度:"+focus_lng.toFixed(5)+","+focus_lat.toFixed(5)+"&nbsp;&nbsp;&nbsp;";
}
//绘制地图
function map_paint()
{
	var root;	
	var makeup=false;
	var i;
	var j;
	if(	(map_panel_start_x!=$("#"+map_div_id).offset().left)||(map_panel_start_y!=$("#"+map_div_id).offset().top)
			||(map_panel_size_x!=parseInt($("#"+map_div_id).width()))||(map_panel_size_y!=parseInt($("#"+map_div_id).height()))
			||(map_max_tile_x!=Math.ceil(map_panel_size_x/256)+1)||(map_max_tile_y!=Math.ceil(map_panel_size_y/256)+1))
	{
		map_panel_start_x=$("#"+map_div_id).offset().left;		
		map_panel_start_y=$("#"+map_div_id).offset().top;
		map_panel_size_x=parseInt($("#"+map_div_id).width());
		map_panel_size_y=parseInt($("#"+map_div_id).height());
	
		map_max_tile_x=Math.ceil(map_panel_size_x/256)+1;		//覆盖地图显示所需瓦片数目，x方向
		map_max_tile_y=Math.ceil(map_panel_size_y/256)+1;
		
		map_source_widget.style.left=map_panel_size_x-110+"px";
	}
	//获取瓦片对象
	for(j=0;j<map_max_tile_y;j++)
	{
		for(i=0;i<map_max_tile_x;i++)
		{
			root=tile_root(Math.floor(map_to_whole_x/256)+i,Math.floor(map_to_whole_y/256)+j,map_source_type);
			if(root==null)
			{
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.visibility="hidden";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.visibility="hidden";
			}
			else 
			{
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.visibility="visible";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.backgroundImage="url("+root+")";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.position="absolute";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.left=map_to_panel_x+i*256+"px";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.top=map_to_panel_y+j*256+"px";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.width=256+"px";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.height=256+"px";
				map_panel_widget.childNodes[1].childNodes[j*map_max_tile_x+i].style.zIndex="99";
				
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.visibility="visible";
				if(map_source_type==0)
					map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.backgroundImage="url("+root.replace("roadmap","overlay_r")+")";
				else if(map_source_type==1)
					map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.backgroundImage="url("+root.replace("satellite","overlay_s").replace("jpg","png")+")";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.position="absolute";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.left=map_to_panel_x+i*256+"px";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.top=map_to_panel_y+j*256+"px";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.width=256+"px";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.height=256+"px";
				map_panel_widget.childNodes[2].childNodes[j*map_max_tile_x+i].style.zIndex="99";
			}
		}
	}
	rap.repaint_overlay();
	map_zoomAndPan_widget.childNodes[3].childNodes[0].style.top=144-8*map_current_layer+"px";
    //添加	
}
//瓦片路径
function tile_root(i,j,type)
{
	//构建地图图片名字
	var root=null;
	if(type==0)
	{
		if (i<0||i>=parseInt(map_info[map_current_layer][1])/256||j<0||j>=parseInt(map_info[map_current_layer][2])/256)
		{
			if(map_current_layer>12||map_current_layer<9)//13级以上和9级以下不做底图补偿
				root="../static/mapService/images/icon/map_no_road_tile.png";//判断是否越界
		}
		else root="../static/mapService/images/map/roadmap/" +map_current_layer+"/"+(parseInt(map_info[map_current_layer][4])+i)+"/"+(parseInt(map_info[map_current_layer][3])+j)+ ".png";
	}
	else if(type==1)//卫星图
	{
		if (i<0||i>=parseInt(map_info[map_current_layer][1])/256||j<0||j>=parseInt(map_info[map_current_layer][2])/256)
		{
			if(map_current_layer>12||map_current_layer<9)//13级以上和9级以下不做底图补偿
				root="../static/mapService/images/icon/map_no_satellite_tile.png";//判断是否越界
		}
		else root="../static/mapService/images/map/satellite/" +map_current_layer+"/"+(parseInt(map_info[map_current_layer][4])+i)+"/"+(parseInt(map_info[map_current_layer][3])+j)+ ".jpg";
		
	}
	return root;
}
//经度到像素X值
function lng_to_pixel(lng,zoom) 
{
	return Math.floor((parseFloat(lng) + 180) * (256 << zoom) / 360);
}
//像素X到经度
function pixel_to_lng(pixelX,zoom) 
{
	return pixelX * 360 / (256 << zoom) - 180;
}
//经度到像素y值
function lat_to_pixel(lat,zoom) 
{  
	var siny = Math.sin(parseFloat(lat) * Math.PI / 180);  
	var  y = Math.log((1 + siny) / (1 - siny));  
	return Math.floor((128 << zoom) * (1 - y / (2 * Math.PI)));  
}  
//像素y到经度
function pixel_to_lat(pixelY,zoom)
{  
	var y = 2 * Math.PI * (1 - pixelY / (128 << zoom));  
	var z = Math.pow(Math.E, y);  
	var siny = (z - 1) / (z + 1);  
	return Math.asin(siny) * 180 / Math.PI;  
}  
//经度到屏幕点x方向
function lng_to_x(lng,zoom)
{
	return lng_to_pixel(lng,zoom)-lng_to_pixel(map_info[zoom][5],zoom)-map_to_whole_x;
}
//屏幕点x方向到经度
function x_to_lng(x,zoom)
{
	return pixel_to_lng(map_to_whole_x+x+lng_to_pixel(map_info[zoom][5],zoom),zoom);
}
//纬度到屏幕点y方向
function lat_to_y(lat,zoom)
{
	return lat_to_pixel(lat,zoom)-lat_to_pixel(map_info[zoom][8],zoom)-map_to_whole_y;
}
//屏幕点y方向到纬度
function y_to_lat(y,zoom)
{
	return pixel_to_lat(map_to_whole_y+y+lat_to_pixel(map_info[zoom][8],zoom),zoom);
}
//经纬度2点到实际距离
function lnglat_to_kilometer(lngA,latA,lngB,latB)
{
	 // earth's mean radius in KM  
    var r = 6378.137;  
    var lat1 = parseFloat(lngA) / 180 * Math.PI;   
    var lng1 = parseFloat(latA) / 180 * Math.PI;   
    var lat2 = parseFloat(lngB) / 180 * Math.PI;  
    var lng2 = parseFloat(latB) / 180 * Math.PI;  
    var d1 = Math.abs(lat1 - lat2);  
    var d2 = Math.abs(lng1 - lng2);  
    var p = Math.pow(Math.sin(d1 / 2), 2) + Math.cos(lat1)* Math.cos(lat2) * Math.pow(Math.sin(d2 / 2), 2);  
    var dis = r * 2 * Math.asin(Math.sqrt(p));  
    return dis;  
}
//地图类
function EzMap(map_div_id_in)
{
	//数据初始化
	map_div_id=map_div_id_in;								//父div的id
	map_max_layer=map_info.length-1;										//最大地图放大级数
	map_current_layer=11;									//地图当前级数

	map_panel_start_x=$("#"+map_div_id).offset().left;		
	map_panel_start_y=$("#"+map_div_id).offset().top;
	
	map_panel_size_x=parseInt($("#"+map_div_id).width());
	map_panel_size_y=parseInt($("#"+map_div_id).height());

	map_max_tile_x=Math.ceil(map_panel_size_x/256)+1;		//覆盖地图显示所需瓦片数目，x方向
	map_max_tile_y=Math.ceil(map_panel_size_y/256)+1;		//覆盖地图显示所需瓦片数目，y方向

	
	map_to_panel_x=0;										//当前显示最左上角地图块，相对地图panel的位置，x方向
	map_to_panel_y=0;										//当前显示最左上角地图块，相对地图panel的位置，y方向
	map_to_whole_x=0										//当前显示地图块，整个地图的位置，x方向
	map_to_whole_x_premove=0;								//当前显示地图块，整个地图的位置，x方向，拖动前位置
	map_to_whole_y=0										//当前显示地图块，整个地图的位置，y方向
	map_to_whole_y_premove=0;								//当前显示地图块，整个地图的位置，y方向，拖动前位置
	
	map_mouse_down_x=0;										//地图拖动时使用，标示鼠标是否按下位置，相对于显示器左上角，像素为单位，x方向
	map_mouse_down_y=0;										//地图拖动时使用，标示鼠标是否按下位置，相对于显示器左上角，像素为单位，y方向

	//设置地图画板参数
	map_load_info();	
	
	//设置地图画笔
	map_pen=new Pen("#D51900",5,0.7,"white",1,null);//color,weight,opacity,fillcolor,arrow,dash
}
EzMap.prototype = 
{
	//地图重置
	/***************************************************************************************************
	Void} MapReset() 
	函数功能：由于地图的相对屏幕位置或者地图所需显示宽高变化，需要调整地图
	Returns:
	{Void} 
	****************************************************************************************************/ 
	MapReset:function()
	{
		map_panel_start_x=$("#"+map_div_id).offset().left;		
		map_panel_start_y=$("#"+map_div_id).offset().top;
		

		map_panel_size_x=parseInt($("#"+map_div_id).width());
		map_panel_size_y=parseInt($("#"+map_div_id).height());

		map_max_tile_x=Math.ceil(map_panel_size_x/256)+1;		//覆盖地图显示所需瓦片数目，x方向
		map_max_tile_y=Math.ceil(map_panel_size_y/256)+1;		//覆盖地图显示所需瓦片数目，y方向
		map_paint();
	},
	//地图控件API
	/***************************************************************************************************
	Void} showMapControl() 
	函数功能：显示一般地图控件。一般地图控制控件包括：各个级别按钮、放大一个级别按钮和缩小一个级别按钮。
	Returns:
	{Void} 
	****************************************************************************************************/ 
	showMapControl:function()
	{

	},
	/***************************************************************************************************
	{Void} hideMapControl() 
	函数功能：隐藏地图操作控件，包括一般地图控件、简化地图控件和标准地图控件。
	Returns:
	{Void} 
	****************************************************************************************************/ 
	hideMapControl:function()
	{

	},
	
	/***************************************************************************************************
	{Void} showCopyright() 
	函数功能：显示版权信息于地图控件的左下角
	Returns:
	{Void}
	****************************************************************************************************/ 
	showCopyright:function()
	{
	},
	/***************************************************************************************************
	{Void} hideCopyright() 
	函数功能：隐藏版权信息
	Returns:
	{Void} 
	****************************************************************************************************/ 
	hideCopyright:function()
	{
	},
	/***************************************************************************************************
	{Void} showMapScale() 
	函数功能：显示比例尺信息于地图的右下角
	Returns:
	{Void} 
	****************************************************************************************************/ 
	showMapScale:function()
	{
	},
	/***************************************************************************************************
	{Void} hideMapScale() 
	函数功能：隐藏比例尺信息
	Returns:
	{Void} 
	****************************************************************************************************/ 
	hideMapScale:function()
	{
	},
	/***************************************************************************************************
	{Void} showMapServer() 
	函数功能：显示地图右上角上角地图服务按钮
	Returns:
	{Void} 
	****************************************************************************************************/ 
	showMapServer:function()
	{
	},
	/***************************************************************************************************
	{Void} hideMapServer() 
	函数功能：隐藏地图右上角上角地图服务按钮
	Returns:
	{Void} 
	****************************************************************************************************/ 
	hideMapServer:function()
	{
	},
	/***************************************************************************************************
	{Void} switchMapServer(iIndex) 
	函数功能：右上角地图服务的切换。
	Parameters:
	{Int} iIndex 
	参数含义：右上角地图服务的索引,最左边的为0
	参数省略：不可以省略
	Returns:
	{Void} 
	****************************************************************************************************/ 
	switchMapServer:function()
	{
	},
	
	//地图操作API
	/***************************************************************************************************
	{Void} zoomIn() 
	函数功能：地图放大一个级别
	Returns:
	{Void} 
	****************************************************************************************************/ 
	zoomIn:function(){
		this.zoomTo(this.getZoomLevel()+1);
	},
	/***************************************************************************************************
	{Void} zoomInExt() 
	函数功能：通过用户在地图上交互的绘制矩形，对地图进行放大。函数执行后，原始焦点对象失去焦点，焦点变为地图控件。
	Returns:
	{Void} 
	****************************************************************************************************/ 
	zoomInExt:function(){
		this.changeDragMode('zoomInExt');
		document.getElementById(map_div_id).focus();
	},
	/***************************************************************************************************
	{Void} zoomOut() 
	函数功能：地图缩小一个级别
	Returns:
	{Void} 
	****************************************************************************************************/ 
	zoomOut:function(){
		this.zoomTo(this.getZoomLevel()-1);
	},
	/***************************************************************************************************
	{Void}  zoomOutExt() 
	函数功能：通过用户在地图上交互的绘制矩形，对地图进行缩小。函数执行后，原始焦点对象失去焦点，焦点变为地图控件。
	Returns:
	{Void} 
	****************************************************************************************************/ 
	zoomOutExt:function(){
		this.changeDragMode('zoomOutExt');
		document.getElementById(map_div_id).focus();
	},
	/***************************************************************************************************
	{Void} zoomTo(zoomLevel) 
	函数功能：地图缩放到指定级别
	Parameters:
	{Int} zoomLevel 
	参数含义：缩放到的级别
	参数省略：不可以省略
	Returns:
	{Void} 
	****************************************************************************************************/ 
	zoomTo:function(level){  
		if(level<1)
			level=1;
		if(level>map_max_layer)
			level=map_max_layer;
		map_zoom_adjust(map_panel_size_x/2+map_panel_start_x,map_panel_size_y/2+map_panel_start_y,map_current_layer,level)
		map_current_layer=parseInt(level);
		map_paint();
	},
	/***************************************************************************************************
	{Void	pan(x, y) 
	函数功能：平移地图或设置地图状态为平移状态
	函数说明：参数为空的情况下设置地图操作状态为平移状态如果存在参数x,y,则相应向X,Y轴方向移动x和y的距离增量。其中地图左下为移动距离相对的原点，即当参数x和y均为正数的时视野是向左下角移动，当参数x和y均为负数时地图向右上角移动（X和Y方向移动的单位为像素） 
	Parameters:
	{Float} x 
	参数含义：X轴方向上的移动增量
	参数省略：可以省略
	{Float} y 
	参数含义：Y轴方向上的移动增量
	参数省略：可以省略
	Returns:
	{Void} 
	****************************************************************************************************/ 
	pan:function(x, y){
		if(x!=undefined&&x!=undefined)
		{
			map_to_whole_x+=x;	
			map_to_whole_y-=y;
			map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
			map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
			map_paint();
		}
	},
	/***************************************************************************************************
	Void} measureLength(callback) 
	函数功能：设置地图操作状态为测距状态
	函数说明：参数要是省略时，通过一个alert来返回测量值
	Parameters:
	{Function} callback 
	参数含义：回调函数，其中arguments[0]参数用来返回测量的距离
	参数省略：可以省略
	回调函数原型：callback(vStrMeasureLength)
	vStrMeasureLength {String} : 用来返回测量的距离
	Returns:
	{Void} 
	****************************************************************************************************/ 
	measureLength:function(callback){
	
	},
	/***************************************************************************************************
	{Void} measureArea(callback) 
	函数功能：设置地图操作状态为测量面积状态
	函数说明：参数要是省略时，通过一个alert来返回测量值
	Parameters:
	{Function} callback 
	参数含义：回调函数，其中arguments[0]参数用来返回测量的面积
	参数省略：可以省略
	回调函数原型：callback(vStrMeasureArea)
	vStrMeasureArea {String} : 用来返回测量的面积
	Returns:
	{Void}
	****************************************************************************************************/ 
	measureArea:function(callback){
	
	},
	/***************************************************************************************************
	{Void} fullExtent() 
	函数功能：设置地图为全图显示
	Returns:
	{Void}
	****************************************************************************************************/ 
	fullExtent:function(){
		for(var i=map_max_layer;i>0;i--)
		{
			if(parseInt(map_info[i][2])<map_panel_size_x)
			{
					this.centerAndZoom(new Point((map_info[i][5]/2+map_info[i][7]/2),(map_info[i][6]/2+map_info[i][8]/2)),i);
					return;
			}
		}	
		this.centerAndZoom(new Point((map_info[13][5]/2+map_info[13][7]/2),(map_info[13][6]/2+map_info[13][8]/2)),13);
	},
	/***************************************************************************************************
	{Void} gotoCenter() 
	函数功能：保持当前缩放比例不变，将地图中心平移到地图中心
	Returns:
	{Void} 
	****************************************************************************************************/ 
	gotoCenter:function(){
		map_to_whole_x=map_info[map_current_layer][1]/2-map_panel_size_x/2;									
		map_to_whole_y=map_info[map_current_layer][2]/2-map_panel_size_y/2;	
		map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
		map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
		map_paint();
	},
	/***************************************************************************************************
	{Void} print() 
	函数功能：将当前状态的地图输出到一个新的页面中，便于打印输出
	Returns:
	{Void}
	****************************************************************************************************/ 
	print:function(){
	},
	/***************************************************************************************************
	{Void} clear() 
	函数功能：清除地图上的绘制和加入的对象
	Returns:
	{Void}
	****************************************************************************************************/ 
	clear:function(){
		this.clearOverlays();
	},
	/***************************************************************************************************
	{Void} centerAtLatLng(param1, y) 
	函数功能：在当前地图界别下，地图对中到指定的点处，方法中的参数可以是两个Float坐标值或一个Point对象
	Parameters:
	{Float|Point} param1 
	参数含义：点X轴上的坐标或要对中的Point处
	参数省略：不可以省略
	{Float} y 
	参数含义：点Y轴上的坐标
	参数省略：可以省略
	Returns:
	{Void} 
	****************************************************************************************************/ 
	centerAtLatLng:function(param1, y){
		var lng
		var lat
		if(typeof(param1)=="object")
		{
			lng=parseFloat(param1.x);
			lat=parseFloat(param1.y);
		}
		else
		{
			lng=parseFloat(param1);
			lat=parseFloat(y);
		}	
		if(lng<map_info[map_current_layer][5]||lat<map_info[map_current_layer][6]||lng>map_info[map_current_layer][7]||lat>map_info[map_current_layer][8])
			return ;

		var current_pix_min=lng_to_pixel(map_info[map_current_layer][5],map_current_layer);
		//获取当前状态下的像素值
		map_to_whole_x=	 Math.floor(lng_to_pixel(lng,map_current_layer)-current_pix_min-map_panel_size_x/2);		
		current_pix_min=lat_to_pixel(map_info[map_current_layer][8],map_current_layer);
		//获取当前状态下的像素值
		map_to_whole_y=	Math.floor(lat_to_pixel(lat,map_current_layer)-current_pix_min-map_panel_size_y/2);
		map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
		map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
		map_paint();
	},
	/***************************************************************************************************
	{Void} recenterOrPanToLatLng(point) 
	函数功能：对中到指定的点，如果该点在当前视图上，则进行平移到该点为地图中心
	Parameters:
	{Point} point 
	参数含义：要对中的点
	参数省略：不可以省略
	Returns:
	{Void}
	****************************************************************************************************/ 
	recenterAtLatLng:function(point){
		this.centerAtLatLng(point);
	},
	/***************************************************************************************************
	{Void} centerAtMBR(dInMinX, dInMinY, dInMaxX, dInMaxY) 
	函数功能：对指定的范围进行地图对中
	Parameters:
	{Float|MBR} dInMinX 
	参数含义：指定范围的X轴坐标上的最小值,或者此参数为一个MBR对象，此时以下的参数无效
	参数省略：不可以省略
	{Float} dInMinY 
	参数含义：指定范围的Y轴坐标上的最小值
	参数省略：可以省略
	{Float} dInMaxX 
	参数含义：指定范围的X轴坐标上的最大值
	参数省略：可以省略
	{Point} dInMaxY 
	参数含义：指定范围的Y轴坐标上的最大值
	参数省略：可以省略
	Returns:
	{Void} 
	****************************************************************************************************/ 
	centerAtMBR:function(dInMinX, dInMinY, dInMaxX, dInMaxY){
		var lng
		var lat
		if(typeof(dInMinX)=="object")
		{
			lng=parseFloat(dInMinX.minX/2+dInMinX.maxX/2);
			lat=parseFloat(dInMinX.minY/2+dInMinX.maxY/2);
		}
		else
		{
			lng=parseFloat(dInMinX/2+dInMaxX/2);
			lat=parseFloat(dInMinY/2+dInMaxY/2);
		}	
		if(lng<map_info[map_current_layer][5]||lat<map_info[map_current_layer][6]||lng>map_info[map_current_layer][7]||lat>map_info[map_current_layer][8])
			return ;

		var current_pix_min=lng_to_pixel(map_info[map_current_layer][5],map_current_layer);
		//获取当前状态下的像素值
		map_to_whole_x=	 Math.floor(lng_to_pixel(lng,map_current_layer)-current_pix_min-map_panel_size_x/2);		
		current_pix_min=lat_to_pixel(map_info[map_current_layer][8],map_current_layer);
		//获取当前状态下的像素值
		map_to_whole_y=	Math.floor(lat_to_pixel(lat,map_current_layer)-current_pix_min-map_panel_size_y/2);
		map_to_panel_x=Math.floor(map_to_whole_x/256)*256-map_to_whole_x;
		map_to_panel_y=Math.floor(map_to_whole_y/256)*256-map_to_whole_y;
		map_paint();
	},
	/***************************************************************************************************
	{Point} getCenterPoint() 
	函数功能：返回外包络框的中心点
	Returns: 
	{Point}
	****************************************************************************************************/ 
	getCenterPoint:function(){
		var pre_pix_min=lng_to_pixel(map_info[map_current_layer][5],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var lng=pixel_to_lng(pre_pix_min+map_to_whole_x+map_panel_size_x/2, map_current_layer);
		pre_pix_min=lat_to_pixel(map_info[map_current_layer][8],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var lat=pixel_to_lat(pre_pix_min+map_to_whole_y+map_panel_size_y/2, map_current_layer);
		return new Point(lng, lat); 
	},
	/***************************************************************************************************
	{Point} centerAndZoom() 
	函数功能：设置地图中心点和级数
	Returns: 
	{Void}
	****************************************************************************************************/ 
	centerAndZoom:function(point, zoomLevel) 
	{	
		this.centerAtLatLng(point);	
		this.zoomTo(zoomLevel);
	},
	/***************************************************************************************************
	{Void} openInfoWindowHtml(strHTML) 
	函数功能：显示信息框
	Parameters: 
	{String} strHTML 
	参数含义：显示在信息框时显示的HTML内容
	参数省略：不可以省略
	Returns: 
	{Void}
	****************************************************************************************************/ 
	openInfoWindowHtml:function(strHTML){
	
	},
	
	//获取地图状态API
	/***************************************************************************************************
	{Point} getCenterLatLng() 
	函数功能：获得地图中心的坐标
	Returns:
	{Point} 
	****************************************************************************************************/ 
	getCenterLatLng:function(){
		return new Point((map_info[map_current_layer][5]/2+map_info[map_current_layer][7]/2),(map_info[map_current_layer][6]/2+map_info[map_current_layer][8]/2));
	},
	/***************************************************************************************************
	{MBR} getBoundsLatLng() 
	函数功能：获取当前视窗的边框
	Returns:
	{MBR} 
	****************************************************************************************************/ 
	getSpanLatLng:function(){
		//获取上一状态最小点的像素值
		var pre_pix_min=lng_to_pixel(map_info[map_current_layer][5],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var minX=pixel_to_lng(pre_pix_min+map_to_whole_x, map_current_layer);
		var maxX=pixel_to_lng(pre_pix_min+map_to_whole_x+map_panel_size_x, map_current_layer);
		//计算当前状态最小点的像素值
		pre_pix_min=lat_to_pixel(map_info[map_current_layer][8],map_current_layer);
		//获得鼠标所在点像素值,并计算该店经度
		var maxY=pixel_to_lat(pre_pix_min+map_to_whole_y,map_current_layer);
		var minY=pixel_to_lat(pre_pix_min+map_to_whole_y+map_panel_size_y,map_current_layer);
		
		return new MBR(minX,maxX,minY,maxY)
	},
	/***************************************************************************************************
	getZoomLevel() 
	函数功能：获取地图的当前级别
	Returns:
	{Int}
	****************************************************************************************************/ 
	getZoomLevel:function(){
		return map_current_layer;
	},
	/***************************************************************************************************
	{Int} getLevelOfMBR(dInMinX, dInMinY, dInMaxX, dInMaxY) 
	函数功能：获取指定的范围的级别
	Parameters:
	{Float} dInMinX 
	参数含义：指定范围的X轴坐标最小值
	参数省略：不可以省略
	{Float} dInMinY 
	参数含义：指定范围的Y轴坐标最小值
	参数省略：不可以省略
	{Float} dInMaxX 
	参数含义：指定范围的X轴坐标最大值
	参数省略：不可以省略
	{Float} dInMaxY 
	参数含义：指定范围的Y轴坐标最大值
	参数省略：不可以省略
	Returns:
	{Int} 
	****************************************************************************************************/ 
	getLevelOfMBR:function(dInMinX, dInMinY, dInMaxX, dInMaxY){
		return map_current_layer;
	},
	/***************************************************************************************************
	{String} getDragMode() 
	函数功能：获取当前绘制模式
	Returns:
	{String} 返回值说明：取值为（"measure"：测量；"pan"：平移模式；"drawPoint"：获取坐标点；"drawCircle"：画圆；"drawRect"：画矩形；"drawPolyline"：画线；"drawPolygon"：画多边形）
	****************************************************************************************************/ 
	getDragMode:function(){
		return draw_mode;
	},
	
	//设置地图绘制模式
	/***************************************************************************************************
	{String} getDragMode() 
	函数功能：获取当前绘制模式
	Returns: 
	{Void}
	****************************************************************************************************/ 
	changeDragMode:function(drawmode,inputform1,inputform2,callback,extra){
		draw_mode=drawmode;
		if(inputform1)
		{   
			map_inputform1=inputform1;
		}
		else
		{
			 map_inputform1=null;
		}
		if(inputform2)
		{
			map_inputform2=inputform2;
		}
		else
		{
			 map_inputform2=null;
		}
		if(callback)
		{
			_callback=callback;
		}
		else _callback=null;		
		map_onclick=0;		
		//根据地图模式改变鼠标样式
		switch (draw_mode)
		{
			case "pan":
				document.getElementById(map_div_id).childNodes[0].style.cursor="pointer";
				break;
			case "measure":
				rap.clear_measure_overlay();
				document.getElementById(map_div_id).childNodes[0].style.cursor="url('../static/mapService/images/icon/measure.cur'), auto";
				break;
			case "drawPoint":
				document.getElementById(map_div_id).childNodes[0].style.cursor="auto";
				break;
			case "drawPolyline":
			case "drawPolygon":
			case "drawRect":
			case "drawCircle":
				document.getElementById(map_div_id).childNodes[0].style.cursor="url('../static/mapService/images/icon/draw.cur'), auto";
				break;
			case "zoomInExt":
			case "zoomOutExt":
				document.getElementById(map_div_id).childNodes[0].style.cursor="crosshair";
				break;
			case "drawMarker":
				Marker_src=extra;
				break;
			case "drawText":
				Marker_src=prompt('出入需要标注的文本信息',"");
				break;
		}
	},
		
	//信息叠加
	/***************************************************************************************************
	{Void} addOverlay(overlay, bDisRemovable) 
	函数功能：在地图上加入指定的对象，放入叠加对象的最队尾
	Parameters:
	{iOverLay} overlay 
	参数含义：在当前地图上加入给定的对象，如：Marker、Title、Circle、Polyline、Polygon
	参数省略：不可以省略
	{Boolean} bDisRemovable 
	参数含义：置此对象否可以删除，默认是：false，是可以删除的
	参数省略：可以省略;参数默认值：false
	Returns:
	{Void} 
	****************************************************************************************************/ 
	addOverlay:function(overlay, bDisRemovable)
	{	
		rap.add_overlay(overlay);
		overlay.bDisRemovable=bDisRemovable;
	},
	/***************************************************************************************************
	{Void} removeOverlay(overlay) 
	函数功能：在地图上删除指定的叠加对象
	Parameters:
	{iOverLay} overlay 
	参数含义：指定要删除的对象，如：Marker、Title、Circle、Polyline、Polygon
	参数省略：不可以省略
	Returns:
	{Void}
	****************************************************************************************************/ 
	removeOverlay:function(overlay)
	{	
		rap.remove_overlay(overlay);
	},
	/***************************************************************************************************
	{Void} clearOverlays() 
	函数功能：在地图上删除所有的叠加对象
	Returns:
	{Void} 
	****************************************************************************************************/ 
	clearOverlays:function()
	{	
		rap.clear_overlay();
	},
	/***************************************************************************************************
	{[]iOverLay} getOverlays() 
	函数功能：获取地图上用户添加的几何对象，标注对象和专题图对象。
	Returns:
	{[]iOverLay}
	****************************************************************************************************/ 
	getOverlays:function()
	{	
		return rap.get_overlay();
	},
	/***************************************************************************************************
	{iOverLay} getCurrentEditor() 
	函数功能：获取当前编辑的对象
	Returns:
	{iOverLay}
	****************************************************************************************************/ 
	getCurrentEditor:function()
	{	
		return rap.get_last_overlay();
	},
	//信息查询、编辑
	/***************************************************************************************************
	{Void} query(queryObj, callback) 
	函数功能：通过矢量地图服务进行查询，如：空间查询和属性查询等
	Parameters:
	{QueryObject|[]QueryObject} queryObj 
	参数含义：查询对象
	参数省略：不可以省略
	{Function} callback 
	参数含义：回调函数，查询操作完成后调用此函数，无返回值
	参数省略：不可以省略
	回调函数原型：callback(vBIsOK, vRequestObj)
	vBIsOK ：用于输出out {Boolean} 可以省略，用于返回查询成功与否
	vRequestObj ：用于输入in {QueryObject|[]QueryObject} 可以省略，在getQueryResult方法中用到
	Returns:
	{Void} 
	****************************************************************************************************/ 
	query:function(queryObj, callback)
	{
	},
	/***************************************************************************************************
	{Void} edit(editObj, callback) 
	函数功能：通过矢量地图服务进行数据源的编辑
	Parameters:
	{EditObject|[]EditObject} editObj 
	参数含义：编辑对象
	参数省略：不可以省略
	{Function} callback 
	参数含义：回调函数，通过参数bIsOK来返回编辑操作成功与否，true表示编辑成功，否则编辑失败
	参数省略：不可以省略
	回调函数原型：callback(vBIsOK)
	vBIsOK ：用于输出out {Boolean} 可以省略，用于返回更新状态成功与否
	Returns:
	{Void} 
	****************************************************************************************************/ 
	edit:function(editObj, callback)
	{
	},
	/***************************************************************************************************
	{[]EzLayer} getQueryResult(queryObj) 
	函数功能：根据查询对象或者查询对象数组获取查询结果
	Parameters:
	{QueryObject|[]QueryObject} queryObj 
	参数含义：查询对象(如果此参数省略时，即获此次查询的全部结果，即一个[]Layer。此参数主要是针对查询对象为一个QueryObject)
	参数省略：可以省略
	Returns:
	{[]EzLayer}
	****************************************************************************************************/ 
	getQueryResult:function(queryObj)
	{
	},
	/***************************************************************************************************
	{Void} setEzLayer(pEzLayerArr) 
	函数功能：设置地图对象中包含的空间对象图层
	Parameters:
	{[]EzLayer} pEzLayerArr 
	参数含义：空间对象图层数组
	参数省略：不可以省略
	Returns:
	{Void}
	****************************************************************************************************/ 
	setEzLayer:function(pEzLayerArr)
	{
	},
	
	//2.2.9	监听地图状态变化操作
	/***************************************************************************************************
	{Void} addMapChangeListener(func) 
	函数功能：增加地图状态变化时执行的操作
	Parameters:
	{Function} func 
	参数含义：回调函数，用于监听地图状态变换时（包括地图拖放、放大、缩小等地图状态变换）响应此函数
	参数省略：不可以省略
	回调函数原型：func()
	Returns:
	{Void}
	****************************************************************************************************/ 
	addMapChangeListener:function(func)
	{
	},
	/***************************************************************************************************
	{Void} removeMapChangeListener(func) 
	函数功能：删除地图状态变化时执行的操作
	Parameters:
	{Function} func 
	参数含义：回调函数
	参数省略：不可以省略
	回调函数原型：func()
	Returns:
	{Void}
	****************************************************************************************************/ 
	removeMapChangeListener:function(func)
	{
	}
}
/***************************************************************************************************
名称 graph.js
描述 用于实现绘图对象，包括点point和MBR，即点和矩形
时间 2014-04-28
****************************************************************************************************/ 
/***************************************************************************************************
pen类，画笔类 
****************************************************************************************************/ 
function Pen(color,weight,opacity,fillcolor,arrow,dash){
	this.color=color;
	this.weight=weight;
	this.opacity=opacity;
	this.fillcolor=fillcolor;
	this.arrow=arrow;
	this.dash=dash;
}
Pen.prototype = 
{
}
/***************************************************************************************************
一个点代表一个二维的坐标，由 x 和 y 坐标表示
****************************************************************************************************/ 
function Point(x,y){
	this.x = parseFloat(x);
	this.y = parseFloat(y);
}
/***************************************************************************************************
MBR 代表一个外包罗筐的边界.
****************************************************************************************************/ 
//用给最小最大坐标创建一个对象实例
function MBR(minX,minY,maxX,maxY){
	this.minX = parseFloat(minX);
	this.minY = parseFloat(minY);
	this.maxX = parseFloat(maxX);
	this.maxY = parseFloat(maxY);
}
MBR.prototype = 
{
	//获取 MBR 的中心点;Point 类型
	centerPoint:function(){ 
		return new Point(this.minX/2+this.maxX/2, this.minY/2+this.maxY/2);
	},
	//获取 X 方向的跨度
	getSpanX:function(){  
		return (this.maxX-this.minX);
	},
	//获取 Y 方向的跨度
	getSpanY:function(){  
		return (this.maxY-this.minY);
	},
	//E 为小数:0~10 MBR 中心扩大其边框
	scale:function(e){
		var center=new Point(this.minX/2+this.maxX/2, this.minY/2+this.maxY/2);
		this.minX=center.x-e*(center.x-this.min.x);
		this.maxX=center.x+e*(this.max.x-center.x);	
		this.minY=center.Y-e*(center.Y-this.min.Y);
		this.maxY=center.Y+e*(this.max.Y-center.Y);	
	},
	//是否包含 pMBR，返回类型：boolean
	containsBounds:function(pMBR){  
		if(this.minX<pMBR.minX&&this.maxX>pMBR.maxX&&this.minY<pMBR.minY&&this.maxY>pMBR.maxY)
			return true;
		else return false;
	},
	//是否包含点，返回类型：boolean
	containsPoint:function(p){
		if(this.minX<p.x&&this.maxX>p.x&&this.minY<p.y&&this.maxY>p.y)
			return true;
		else return false;
	}
}
/***************************************************************************************************
Icon类，图标类 
****************************************************************************************************/ 
function Icon(){
	this.image="";
	this.width=0;
	this.height=0;
	this.leftOffset=0;
	this.topOffset=0;
}
Icon.prototype = 
{
}
/***************************************************************************************************
名称 ioverlay.js
描述 用于实现覆盖物对象，地图上所能描述的对象，如：Marker、Title、Circle、Polyline、Polygon
时间 2014-04-28
****************************************************************************************************/ 
/***************************************************************************************************
iOverlay 该对象为叠加信息类的积累
****************************************************************************************************/ 
function iOverlay(){
	this.center=null;
	this.opacity=1;
	this.iIndex=0; //显示叠堆序列
	this.index=0;	//存储索引
	this.click_callback=null;
	this.dblclick_callback=null;
	this.mouseover_callback=null;
	this.mouseout_callback=null;
	this.isEdit=true;
}
iOverlay.prototype = 
{
	disableEdit:function()
	{
		this.isEdit=false;
	},
	enableEdit:function()
	{
		this.isEdit=true;
	},
	setCenter:function(point)
	{
		this.center=point;
	},
	getCenter:function()
	{
		return this.center;
	},
	setZIndex:function(iIndex)
	{
		this.iIndex=iIndex;
		rap.adjust_overlay_zindex();
	},
	getZIndex:function()
	{
		return this.iIndex;
	},
	addListener:function(action, func)
	{
		if(action=="click")
			this.click_callback=func;
		else if(action=="dblclick")
			this.dblclick_callback=func;
		else if(action=="mouseover")
			this.mouseover_callback=func;
		else if(action=="mouseout")
			this.mouseout_callback=func;
	}
}
/***************************************************************************************************
overlay_Point
****************************************************************************************************/ 
//	points 由：经度、纬度、半径组成，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
function Overlay_Point(points,color,weight,opacity,fillcolor){
	this.points = points;
	this.color = color;
	this.weight = weight;
	this.opacity = opacity;
	this.fillcolor = fillcolor;
	this.overlay_type="Point";
	var arr=points.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
}
Overlay_Point.prototype = new iOverlay();

Overlay_Point.prototype.getCenter=function()
{
	return new Point(this.points[0],this.points[1]);
}
Overlay_Point.prototype.getRadius=function()
{
	return new Point(this.points[2]);
}
/***************************************************************************************************
Circle 圆是由中心点和半径组成，
****************************************************************************************************/ 
//	points 由：经度、纬度、半径组成，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
function Circle(points,color,weight,opacity,fillcolor){
	this.points = points;
	this.color = color;
	this.weight = weight;
	this.opacity = opacity;
	this.fillcolor = fillcolor;
	this.overlay_type="Circle";
	var arr=points.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
	
}
Circle.prototype = new iOverlay();

Circle.prototype.getCenter=function()
{
	return new Point(this.points[0],this.points[1]);
}
Circle.prototype.getRadius=function()
{
	return new Point(this.points[2]);
}
/***************************************************************************************************
Marker类，在地图上显示单个标记叠加对象
****************************************************************************************************/ 
//	point 由：经度、纬度，可以是 String 类型；
//	icon 
//	title 标题对象
function Marker(point, icon, title) {
	
	if(typeof(point)=="object")
	{
		this.point=point.x+","+point.y;
		this.setCenter(new Point(point.x,point.y));
		//以经纬度存储具有其方便性,但是在实际重绘中每次绘制对象都要从新进行经纬度到屏幕坐标的换算,存在性能问题,因此添加该图标在每层下的绝对坐标用于快速重绘
		//by R2 2015-4-21
		this.position=new Array();
		for(var i=1;i<=map_max_layer;i++)
		{
			this.position[i]=new Point(lng_to_pixel(point.x,i)-lng_to_pixel(map_info[i][5],i),lat_to_pixel(point.y,i)-lat_to_pixel(map_info[i][8],i));
			//alert(position[i].x+" "+position[i].y);
		}
		if(title)
			this.title=title;
		this.div=document.createElement('img');
		map_canvas.appendChild(this.div);
		if(icon)
			this.icon=icon;
		
		if(title)
			this.div.name=title.name;
		this.div.style.zIndex="201";
	}
	else if(typeof(point)=="string")
	{
		this.point=point;
		var arr=point.split(",");
		this.setCenter(new Point(arr[0],arr[1]));
		this.title=title;
		this.div=document.createElement('img');
		map_canvas.appendChild(this.div);
		if(icon)
		{
			this.icon=icon;
		}
		
		if(title)
			this.div.name=title.name;
		this.div.style.zIndex="201";
		

	}
	else
	{
		alert("Ezmap:Marker类point参数类型错误");
		return;
	}
	this.overlay_type="Marker";
 
}
Marker.prototype = new iOverlay();
Marker.prototype.setPoint=function(point)
{
	this.point=point;
}
Marker.prototype.setIcon=function(icon)
{
	var arr=this.point.split(",");
	var lng=parseFloat(arr[0]);
	var lat=parseFloat(arr[1]);

	if(icon)
	{
		this.div.src=icon.image;
		this.div.style.left=lng_to_x(lng,map_current_layer)+icon.leftOffset-icon.width/2+"px";
		this.div.style.top=lat_to_y(lat,map_current_layer)+icon.topOffset-icon.height/2+"px";
		this.div.style.width=icon.width+"px";
		this.div.style.height=icon.height+"px";
		this.icon=icon;
	}
		
}
Marker.prototype.getTitle=function()
{
	return this.title;
}
Marker.prototype.hideIcon=function()
{

	this.div.style.visibility="hidden";
}
Marker.prototype.showIcon=function()
{
	this.div.style.visibility="visible";
}
Marker.prototype.hideTitle=function()
{
	if(this.title)
	{
		this.ifShowTitle=false;
		this.title.div.style.visibility="hidden";
		map_paint();
	}
}
Marker.prototype.showTitle=function()
{
	if(this.title)
	{
		this.ifShowTitle=true;
		this.title.div.style.visibility="visible";
		map_paint();
	}
}
/***************************************************************************************************
Polygon 多边形
****************************************************************************************************/ 
//	points 多边形端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
function Polygon(points,color,weight,opacity,fillcolor){
	this.points = points;
	this.color = color;
	this.weight = weight;
	this.opacity = opacity;
	this.fillcolor = fillcolor;
	this.overlay_type="Polygon";
	var arr=points.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
	this.dash="";
 
}
Polygon.prototype = new iOverlay();
Polygon.prototype.setDashStyle=function(type)
{
	if(type=="shortdot")
		this.dash='.';
}
/***************************************************************************************************
Polyline 折线
****************************************************************************************************/ 
//	points 折线端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	arrow 是否使用箭头 1是 0否
function Polyline(points,color,weight,opacity,arrow){
	this.points = points;
	this.color = color;
	this.weight = weight;
	this.opacity = opacity;
	this.arrow = arrow;
	this.overlay_type="Polyline";
	var arr=points.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
	this.dash="111";
}
Polyline.prototype = new iOverlay();
Polyline.prototype.setDashStyle=function(type)
{
	if(type=="shortdot")
		this.dash='.';
}
/***************************************************************************************************
Rectangle  矩形
****************************************************************************************************/ 
//	points 折线端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
function Rectangle(points,color,weight,opacity,fillcolor,dash){
	this.points = points;
	this.color = color;
	this.weight = weight;
	this.opacity = opacity;
	this.fillcolor = fillcolor;
	this.dash = dash;	
	this.overlay_type="Rectangle";
	var arr=points.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
 
}
Rectangle.prototype = new iOverlay();
/***************************************************************************************************
Title 标题类
****************************************************************************************************/ 
//	name 标题名称如:"北京"
// 	fontSize 字体大小:如:14
// 	pos 标题位置（取值范围0~7：分别代表上、左上、左、左下、下、右下、右、右上8个方向）类型：Number 初始默认值：7
//	font 字体,如:"宋体"
// 	color 颜色,如:"red"
//	bgColor 背景颜色 
function Title(name, fontSize, pos, font, color, bgColor, borderColor, borderSize) 
{
	this.name=name;
	this.fontSize=14;
	if(fontSize)
		this.fontSize=fontSize;
	this.pos=pos;
	this.font=font;
	this.color=color;
	this.bgColor=bgColor;
	this.borderColor=borderColor;
	this.borderSize=18;
	if(borderSize)
		this.borderSize=borderSize;	

	this.overlay_type="Title";
	this.div=document.createElement('div');
	map_canvas.appendChild(this.div);
	this.div.style.zIndex="202";
}
Title.prototype = new iOverlay();
Title.prototype.getPoint=function(){
	return this.getCenter();
}
Title.prototype.setPoint=function(str){
	var arr=str.split(",");
	this.setCenter(new Point(arr[0],arr[1]));
}
Title.prototype.setName=function(name){
	this.name=name;
}
Title.prototype.getName=function(name){
	return this.name;
}
/***************************************************************************************************
名称 rapGraphics.js
描述 用于实现绘图相关接口
时间 2014-05-14
****************************************************************************************************/ 

//创建画布，id为画布的父容器(div)，width,height为画布的宽度和高度
function rapGraphics(id,width,height)
{
    this.paper=Raphael(id,width,height);
	this.user_overlay=[]; 	//用于保存用户覆盖物对象信息 用户可编辑
	this.system_overlay=[]; //用于保存系统覆盖物对象信息 用户不可编辑，包括提示性title marker 测距所绘制的overlay
	//以Zindex序列排列 数组越前zindex越大 同zindex越后面添加优先级越高
}
//添加图层 
rapGraphics.prototype.add_overlay=function(overlay_in)
{	
	for(var i=0;i<this.user_overlay.length;i++)
	{
		if(overlay_in.getZIndex()>=this.user_overlay[i].getZIndex())
		{
			overlay_in.index=this.user_overlay.length;
			this.user_overlay.splice(i,0,overlay_in);
			this.repaint_overlay();
			return;
		}
	}
	overlay_in.index=this.user_overlay.length
	this.user_overlay.push(overlay_in);
	this.repaint_overlay();
}
//添加系统图层 
rapGraphics.prototype.add_system_overlay=function(overlay_in)
{	
	for(var i=0;i<this.system_overlay.length;i++)
	{
		if(overlay_in.getZIndex()>=this.system_overlay[i].getZIndex())
		{
			overlay_in.index=this.system_overlay.length;
			this.system_overlay.splice(i,0,overlay_in);
			this.repaint_overlay();
			return;
		}
	}
	overlay_in.index=this.system_overlay.length
	this.system_overlay.push(overlay_in);
	this.repaint_overlay();
}

//删除图层
rapGraphics.prototype.remove_overlay=function(overlay_out)
{	
	for(var i=0;i<this.user_overlay.length;i++)
	{
		if(overlay_out==this.user_overlay[i])
		{
			if(this.user_overlay[i].isEdit==true)//如果图层是可以编辑的状态，则清除
			{
				if(this.user_overlay[i].overlay_type=="Marker"||this.user_overlay[i].overlay_type=="Title")
				{
					if(this.user_overlay[i].title!=null)
						map_canvas.removeChild(this.user_overlay[i].title.div);
					map_canvas.removeChild(this.user_overlay[i].div);
				}
				this.user_overlay.splice(i,1);
				this.repaint_overlay();
			}
			return;
		}
	}
}
//清除测距图层
rapGraphics.prototype.clear_measure_overlay=function()
{	
	for(var i=this.system_overlay.length-1;i>=0;i--)
	{
		if(this.system_overlay[i].isEdit==true&&this.system_overlay[i].getZIndex()<=-2)//如果图层是可以编辑的状态，则清除
		{
			if(this.system_overlay[i].overlay_type=="Marker"||this.system_overlay[i].overlay_type=="Title")
			{
				if(this.system_overlay[i].title!=null)
					map_canvas.removeChild(this.system_overlay[i].title.div);
				map_canvas.removeChild(this.system_overlay[i].div);
			}
			this.system_overlay.splice(i,1);
		}
	}
	this.repaint_overlay();
}
//清除所有图层
rapGraphics.prototype.clear_overlay=function()
{	
	for(var i=this.user_overlay.length-1;i>=0;i--)
	{
		if(this.user_overlay[i].isEdit==true)//如果图层是可以编辑的状态，则清除
		{
			if(this.user_overlay[i].overlay_type=="Marker"||this.user_overlay[i].overlay_type=="Title")
			{
				if(this.user_overlay[i].title!=null)
					map_canvas.removeChild(this.user_overlay[i].title.div);
				map_canvas.removeChild(this.user_overlay[i].div);
			}
			this.user_overlay.splice(i,1);
		}
	}
	this.clear_measure_overlay()
	this.repaint_overlay();
	
}
//获取所有图层
rapGraphics.prototype.get_overlay=function()
{	
	return this.user_overlay;
}
//获取最后图层
rapGraphics.prototype.get_last_overlay=function()
{	
	for(var i=0;i<this.user_overlay.length;i++)
	{
		if(this.user_overlay.length-1==this.user_overlay[i].index)
		{
			return this.user_overlay[i];
		}
	}
}
//根据图层zindex，调整图层序列顺序，保证有序
//基本有序数组，冒泡排序效率较高
rapGraphics.prototype.adjust_overlay_zindex=function()
{	
	var temp;
	for(var i=0;i<this.user_overlay.length;i++)
	{
		for(var j=0;j<this.user_overlay.length-i-1;j++)
		{
			if(this.user_overlay[i].getZIndex()<this.user_overlay[i+1].getZIndex())
			{
				temp=this.user_overlay[i];
				this.user_overlay[i]=this.user_overlay[i+1];
				this.user_overlay[i+1]=temp;
			}
		}
	}
}
//重绘图层
rapGraphics.prototype.repaint_overlay=function()
{
	this.paper.clear();
	var i;
	var element;
		//重绘用户图层
	for(i=this.user_overlay.length-1;i>=0;i--)
	{
		switch(this.user_overlay[i].overlay_type)
		{
			case "Marker":
				element=this.drawMarker(this.user_overlay[i].div,this.user_overlay[i].position[map_current_layer],this.user_overlay[i].icon);
				if(this.user_overlay[i].getCenter()!=null&&this.user_overlay[i].ifShowTitle==true)
					this.drawTitle(this.user_overlay[i].title.div,this.user_overlay[i].getCenter().x+","+y_to_lat((lat_to_y(this.user_overlay[i].getCenter().y,map_current_layer)-this.user_overlay[i].icon.height),map_current_layer),this.user_overlay[i].title.name,this.user_overlay[i].title.fontSize,this.user_overlay[i].title.pos,this.user_overlay[i].title.font,this.user_overlay[i].title.color,this.user_overlay[i].title.bgColor,this.user_overlay[i].title.borderColor,this.user_overlay[i].title.borderSize);
			break;
			case "Point":
				element=this.drawPoint(this.user_overlay[i].points,this.user_overlay[i].color,this.user_overlay[i].weight,this.user_overlay[i].opacity,this.user_overlay[i].fillcolor);
			break;	
			case "Circle":
				element=this.drawCircle(this.user_overlay[i].points,this.user_overlay[i].color,this.user_overlay[i].weight,this.user_overlay[i].opacity,this.user_overlay[i].fillcolor);
			break;	
			case "Polygon":
				element=this.drawPolygon(this.user_overlay[i].points,this.user_overlay[i].color,this.user_overlay[i].weight,this.user_overlay[i].opacity,this.user_overlay[i].fillcolor);
			break;	
			case "Polyline":
				element=this.drawPolyline(this.user_overlay[i].points,this.user_overlay[i].color,this.user_overlay[i].weight,this.user_overlay[i].opacity,this.user_overlay[i].arrow,this.user_overlay[i].dash);
			break;	
			case "Rectangle":
				element=this.drawRectangle(this.user_overlay[i].points,this.user_overlay[i].color,this.user_overlay[i].weight,this.user_overlay[i].opacity,this.user_overlay[i].fillcolor,this.user_overlay[i].dash);
			break;	
			case "Title":
				if(this.user_overlay[i].getCenter()!=null&&this.ifShowTitle==true)
					element=this.drawTitle(this.user_overlay[i].div,this.user_overlay[i].getCenter().x+","+this.user_overlay[i].getCenter().y,this.user_overlay[i].name,this.user_overlay[i].fontSize,this.user_overlay[i].pos,this.user_overlay[i].font,this.user_overlay[i].color,this.user_overlay[i].bgColor,this.user_overlay[i].borderColor,this.user_overlay[i].borderSize);
			break;
		}
		
		if(element)
		{
			if(this.user_overlay[i].overlay_type=="Marker")
			{
				if(this.user_overlay[i].click_callback!=null)
					element.onclick=this.user_overlay[i].click_callback;
				if(this.user_overlay[i].dblclick_callback!=null)
					element.ondblclick=this.user_overlay[i].dblclick_callback;
				if(this.user_overlay[i].mouseover_callback!=null)
					element.onmouseover=this.user_overlay[i].mouseover_callback;
				if(this.user_overlay[i].mouseout_callback!=null)
					element.onmouseout=this.user_overlay[i].mouseout_callback;
			}
			else
			{
				if(this.user_overlay[i].click_callback!=null)
					element.node.onclick=this.user_overlay[i].click_callback;
				if(this.user_overlay[i].dblclick_callback!=null)
					element.node.ondblclick=this.user_overlay[i].dblclick_callback;
				if(this.user_overlay[i].mouseover_callback!=null)
					element.node.onmouseover=this.user_overlay[i].mouseover_callback;
				if(this.user_overlay[i].mouseout_callback!=null)
					element.node.onmouseout=this.user_overlay[i].mouseout_callback;
			}
		}
		
	}
	//重绘系统图层
	for(i=this.system_overlay.length-1;i>=0;i--)
	{
		switch(this.system_overlay[i].overlay_type)
		{
			case "Marker":
				this.drawMarker(this.system_overlay[i].div,this.system_overlay[i].point,this.system_overlay[i].icon);
				if(this.system_overlay[i].getCenter()!=null&&this.system_overlay[i].title!=null)
					this.drawTitle(this.system_overlay[i].title.div,this.system_overlay[i].getCenter().x+","+y_to_lat((lat_to_y(this.system_overlay[i].getCenter().y,map_current_layer)-this.system_overlay[i].icon.height),map_current_layer),this.system_overlay[i].title.name,this.system_overlay[i].title.fontSize,this.system_overlay[i].title.pos,this.system_overlay[i].title.font,this.system_overlay[i].title.color,this.system_overlay[i].title.bgColor,this.system_overlay[i].title.borderColor,this.system_overlay[i].title.borderSize);
			break;
			case "Point":
				element=this.drawPoint(this.system_overlay[i].points,this.system_overlay[i].color,this.system_overlay[i].weight,this.system_overlay[i].opacity,this.system_overlay[i].fillcolor);
			break;	
			case "Circle":
				element=this.drawCircle(this.system_overlay[i].points,this.system_overlay[i].color,this.system_overlay[i].weight,this.system_overlay[i].opacity,this.system_overlay[i].fillcolor);
			break;	
			case "Polygon":
				element=this.drawPolygon(this.system_overlay[i].points,this.system_overlay[i].color,this.system_overlay[i].weight,this.system_overlay[i].opacity,this.system_overlay[i].fillcolor);
			break;	
			case "Polyline":
				this.drawPolyline(this.system_overlay[i].points,this.system_overlay[i].color,this.system_overlay[i].weight,this.system_overlay[i].opacity,this.system_overlay[i].arrow,this.system_overlay[i].dash);
			break;	
			case "Rectangle":
				this.drawRectangle(this.system_overlay[i].points,this.system_overlay[i].color,this.system_overlay[i].weight,this.system_overlay[i].opacity,this.system_overlay[i].fillcolor,this.system_overlay[i].dash);
			break;	
			case "Title":
				if(this.system_overlay[i].getCenter()!=null)
					this.drawTitle(this.system_overlay[i].div,this.system_overlay[i].getCenter().x+","+this.system_overlay[i].getCenter().y,this.system_overlay[i].name,this.system_overlay[i].fontSize,this.system_overlay[i].pos,this.system_overlay[i].font,this.system_overlay[i].color,this.system_overlay[i].bgColor,this.system_overlay[i].borderColor,this.system_overlay[i].borderSize);
			break;
		}
	}
}
//画图标函数 
//	points 由：经度、纬度 组成String 类型；
//	icon 表示图标信息
rapGraphics.prototype.drawMarker=function(div,point,icon)
{
	var lng=point.x;
	var lat=point.y;
	if(icon)
	{
		div.src=icon.image;//style.backgroundImage="url("+root+")";
		div.style.position="absolute";
		div.style.left=lng-map_to_whole_x+icon.leftOffset-icon.width/2+"px";
		div.style.top=lat-map_to_whole_y+icon.topOffset-icon.height/2+"px";
		div.style.width=icon.width+"px";
		div.style.height=icon.height+"px";
		div.style.zIndex="201";
	}
	return div;
}
//画点函数 
//	points 由：经度、纬度 组成，是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
rapGraphics.prototype.drawPoint=function(points,color,weight,opacity,fillcolor)
{
	var arr=points.split(",");
	var lng=parseFloat(arr[0]);
	var lat=parseFloat(arr[1]);
	var radius=3;
	var point=this.paper.circle(lng_to_x(lng,map_current_layer),lat_to_y(lat,map_current_layer),5);

	point.attr("fill",fillcolor); 
	point.attr("fill-opacity",opacity); 
	point.attr("stroke",color);
	
	return point;
}
//画圆函数 
//	points 由：经度、纬度、半径组成，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
rapGraphics.prototype.drawCircle=function(points,color,weight,opacity,fillcolor)
{
	var arr=points.split(",");
	var lng=parseFloat(arr[0]);
	var lat=parseFloat(arr[1]);
	var radius=parseFloat(arr[2]);
	var circle=this.paper.circle(lng_to_x(lng,map_current_layer),lat_to_y(lat,map_current_layer),(lng_to_x(lng+radius,map_current_layer)-lng_to_x(lng,map_current_layer)));

	circle.attr("fill",fillcolor); 
	circle.attr("fill-opacity",opacity); 
	circle.attr("stroke",color);
	return circle;
}
//根据数组画多边形 
//	points 多边形端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
rapGraphics.prototype.drawPolygon=function(points,color,weight,opacity,fillcolor)
{  
	var arr=points.split(",");
	if(arr.length<4)
		return;
	var lstr="";
	for(var i=0;i<arr.length;)
	{
		if(i==0)
			lstr+="M"+lng_to_x(arr[i],map_current_layer)+" "+lat_to_y(arr[i+1],map_current_layer);
		else
			lstr+="L"+lng_to_x(arr[i],map_current_layer)+" "+lat_to_y(arr[i+1],map_current_layer);
		i+=2;
	}
	lstr+="L"+lng_to_x(arr[0],map_current_layer)+" "+lat_to_y(arr[1],map_current_layer);
	var polygon=this.paper.path(lstr);
	polygon.attr("stroke",color);
	polygon.attr("fill-opacity",opacity);
	polygon.attr("stroke-width",weight);
	polygon.attr("fill",fillcolor); 
	
	return polygon;
}
//根据数组画折线 
//	points 折线端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	arrow 表示是否有箭头，值的范围是 0～1
rapGraphics.prototype.drawPolyline=function(points,color,weight,opacity,arrow,dash)
{  
	var arr=points.split(",");
	if(arr.length<4)
		return;
	var lstr="";
	for(var i=0;i<arr.length;)
	{
		if(i==0)
			lstr+="M"+lng_to_x(arr[i],map_current_layer)+" "+lat_to_y(arr[i+1],map_current_layer);
		else
			lstr+="L"+lng_to_x(arr[i],map_current_layer)+" "+lat_to_y(arr[i+1],map_current_layer);
		i+=2;
	}
	var polyline=this.paper.path(lstr);
	polyline.attr("stroke",color);
	polyline.attr("fill-opacity",opacity);
	polyline.attr("stroke-width",weight);
	if(dash)
		polyline.attr("stroke-dasharray",dash);

	if(arrow==1)
	{
		for(i=0;(i+3)<arr.length;i+=2)
		{
			var x1=lng_to_x(arr[i],map_current_layer);
			var y1=lat_to_y(arr[i+1],map_current_layer);
			var x2=lng_to_x(arr[i+2],map_current_layer);
			var y2=lat_to_y(arr[i+3],map_current_layer);
			var k=(y2-y1)/(x2-x1);
	
			var point_a=new Point(x2-10/Math.pow(1+k*k,1/2),y2-10*Math.abs(k)/Math.pow(1+k*k,1/2))
			if(x2<x1)
				point_a.x=x2+10/Math.pow(1+k*k,1/2);
			if(y2<y1)
				point_a.y=y2+10*Math.abs(k)/Math.pow(1+k*k,1/2);
				
			
			var point_b=new Point(point_a.x+10*k/Math.pow(1+k*k,1/2),point_a.y-10/Math.pow(1+k*k,1/2))
			var point_c=new Point(point_a.x-10*k/Math.pow(1+k*k,1/2),point_a.y+10/Math.pow(1+k*k,1/2))	
			
			var arrow=this.paper.path("M"+x2+" "+y2+"L"+point_b.x+" "+point_b.y+"L"+point_c.x+" "+point_c.y);
			arrow.attr("stroke",color);
			arrow.attr("fill",color);
		}
		
	}

	return polyline;
}
//	points 折线端点，可以是 String 类型；
//	color 表示颜色，支持格式是如"#0000ff"或“red”)；
//	weight 表示线的宽度，它是整形的；
//	opacity 表示线的透明度，浮点型，值的范围是 0～1；
//	fillcolor 为填充的颜色
rapGraphics.prototype.drawRectangle=function(points,color,weight,opacity,fillcolor,dash)
{  
	var arr=points.split(",");
	
	//校准数据
	var temp;
	if(parseFloat(arr[0])>parseFloat(arr[2]))
	{
		temp=arr[0];
		arr[0]=arr[2];
		arr[2]=temp;
	}
	if(parseFloat(arr[1])<parseFloat(arr[3]))
	{
		temp=arr[1];
		arr[1]=arr[3];
		arr[3]=temp;
	}
	var x=lng_to_x(arr[0],map_current_layer);
	var y=lat_to_y(arr[1],map_current_layer);
	var width=lng_to_x(arr[2],map_current_layer)-lng_to_x(arr[0],map_current_layer);
	var height=lat_to_y(arr[3],map_current_layer)-lat_to_y(arr[1],map_current_layer);

	var rectangle=this.paper.rect(x,y,width,height);
	rectangle.attr("stroke",color);
	rectangle.attr("fill-opacity",opacity);
	rectangle.attr("fill",fillcolor); 
	if(dash)
		rectangle.attr("stroke-dasharray","- ");
	return rectangle;
}
//	name 标题名称如:"北京"
// 	fontSize 字体大小:如:14
// 	pos 标题位置（取值范围0~7：分别代表上、左上、左、左下、下、右下、右、右上8个方向）类型：Number 初始默认值：7
//	font 字体,如:"宋体"
// 	color 颜色,如:"red"
//	bgColor 背景颜色 
rapGraphics.prototype.drawTitle=function(div,points,name, fontSize, pos, font, color, bgColor, borderColor, borderSize) 
{
	var arr=points.split(",");
	//画文字
	div.innerHTML=name;
	div.style.position="absolute";
	div.style.left=lng_to_x(arr[0],map_current_layer)-div.offsetWidth/2+"px";
	div.style.top=lat_to_y(arr[1],map_current_layer)-div.offsetHeight+"px";

	div.style.fontSize=fontSize;
	div.style.backgroundColor=bgColor;
	div.style.borderColor=borderColor;
	div.style.borderStyle="solid";
	div.style.borderWidth=borderSize+"px";
	div.style.zIndex="202";

}
